datastax/csharp-driver — pull request #36 by medvekoma (2014-06-24 11:53:18+00:00)
Title: Null values are explicitly inserted in CqlInsert queries

Currently null values are optimized out from CqlInsert queries, which is fine if the row doesn't exists, but creates issues if there is already a row with the same key. Considering the following two insert statements

table.Insert(new Entity() { Key = 1, Value1 = "a", Value2 = "A").Execute();
table.Insert(new Entity() { Key = 1, Value1 = "b", Value2 = null).Execute();

the result will be a mixture of the two updates:

var entity = table.Where(item => item.Key == 1).Execute.Single();
Assert.That(entity.Value1, Is.EqualTo("b"); // this passes
Assert.That(entity.Value2, Is.Null); // this assertion fails, because entity.Value2 preserves its old value ("A")

One could argue that inserts are only used for actual insertion, but Cassandra's upsert model is based on the fact that inserts and updates are equivalent. A null value is data, not just a sign that we don't want to update that field. If one wants to execute a partial update, can create another entity class with a limited number of fields.