A user wanted to know how the C# driver handles columns which are not bound an INSERT statement.
A user wanted to know how the C# driver handles columns which are not bound an INSERT statement.
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.
DataStax Enterprise is powered by the best distribution of Apache Cassandra ™
© 2023 DataStax, Titan, and TitanDB are registered trademarks of DataStax, Inc. and its subsidiaries in the United States and/or other countries.
Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries.
Privacy Policy Terms of Use