A user wanted to know how the C# driver handles columns which are not bound an INSERT statement.
Bringing together the Apache Cassandra experts from the community and DataStax.
Want to learn? Have a question? Want to share your expertise? You are in the right place!
Not sure where to begin? Getting Started
On the insert method you have a boolean parameter called "insertNulls" that controls that behavior:
// Mapper - Mapper class Task InsertAsync<T>(T poco, string executionProfile, bool insertNulls, int? ttl, CqlQueryOptions queryOptions = null) // Linq2Cql - Table<TEntity> class CqlInsert<TEntity> Insert(TEntity entity, bool insertNulls)
For updates, the Mapper generates statements with all the columns that are specified in the mapping configuration so it will bind those parameters to null values when the mapped class properties have null values. You can override this by using the method overloads that allow you to pass a CQL string and therefore specify which columns you want to update:
_mapper.Update<Song>(Cql.New( "SET Artist = ?, ReleaseDate = ?, Title = ? WHERE Id = ?", song.Title, song.Artist, song.ReleaseDate, song.Id));
In Linq2Cql you always have to specify the columns that you want to update so if you don't specify a column, the driver will generate a statement without it, i.e., a null value will not be inserted.
When using statements directly it is up to the user to bind Unset to that particular parameter if they don't want to insert/update that column or to avoid specifying that column in the CQL string.
// using unset var preparedStatement = session.Prepare( @"INSERT INTO table (id, text_sample, int_sample) VALUES (?, ?, ?)"); session.Execute(preparedStatement.Bind(id, Unset.Value, Unset.Value));
With prepared statements specifically, if you don't provide values for all the parameters then the driver will bind Unset to the remaining parameters. Note that Unset is only supported in Apache Cassandra versions 2.2 or later. In earlier versions, an exception will be thrown if you don't provide values for all the parameters on a prepared statement.
5 People are following this question.