Windows Azure Table storage- How to handle CAUTIOUSLY nullable data types
Azure table allows nullable type for int, string and also bool. But we need to provide special attention while updating a table entity.
For example, for a table entity - Student with properties as:
For the first time if I pass "null" for the nullable properties, it will get inserted. But if I first provide some not-null value for the concerned nullable property and then later want to update it with a null value, the old value will get retained because the table service will assume as if no data is provided. And if we really want to update with null then the default approach will not work. So to handle such scenario, in the Save operation we need to pass a change-option as:
This will do insert-or-replace instead of insert-or-merge and thus the concerned property will get updated with null value.
"Save changes" method without any parameter works like insert-or-merge where (for an existing entity) provided property will be updated and for others old value will be merged/retained. And thus when null is passed for any property it is assumed as if it is not provided.
So, this is an approach to work with table entity in which for any property, if null is even considered as a valid value.