How do you update timestamp field in cassandra with C# driver?

Viewed 915

I am trying to update a timestamp field in Cassandra like this:

await new Table<MyEntity>(_session).Where(e => e.Id == entity.Id)
    .Select(u => new MyEntity
    { 
        EndDate = DateTimeOffset.UtcNow
    })
    .Update()
    .ExecuteAsync();

However it throws "Object reference not set to an instance of an object." with cassandra stack trace:

at Cassandra.Data.Linq.CqlExpressionVisitor.GetPropertyValue(MemberExpression node)
at Cassandra.Data.Linq.CqlExpressionVisitor.GetClosureValue(MemberExpression node)
at Cassandra.Data.Linq.CqlExpressionVisitor.AddProjection(Expression node, PocoColumn column)
at Cassandra.Data.Linq.CqlExpressionVisitor.FillUpdateProjection(MemberExpression node)
at Cassandra.Data.Linq.CqlExpressionVisitor.VisitMemberInit(MemberInitExpression node)
at Cassandra.Data.Linq.CqlExpressionVisitor.VisitLambda[T](Expression`1 node)
at Cassandra.Data.Linq.CqlExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at Cassandra.Data.Linq.CqlExpressionVisitor.GetUpdate(Expression expression, Object[]& values, Nullable`1 ttl, Nullable`1 timestamp, MapperFactory mapperFactory)
at Cassandra.Data.Linq.CqlUpdate.GetCql(Object[]& values)
at Cassandra.Data.Linq.CqlCommand.<ExecuteAsync>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

Attempting to update other fields works ok and if I remove the EndDate field from the .Select list it works so there's something I don't get. Is there some sort of special mapping for timestamp required perhaps?

2 Answers

CSHARP-577 fixed some issues with Properties but this question is related to a different issue which is related to static properties - CSHARP-778

Until CSHARP-778 is released, the workaround is to do exactly what you did, i.e., use a local variable.

Related