Note that there are some explanatory texts on larger screens.

plurals
  1. PODefault values for properties in Azure Table Storage
    text
    copied!<p>I am using Azure table storage and have questions about how nulls and default values for entities work. </p> <p>Specifically, I have a class that extends <code>TableServiceEntity</code>. The default constructor for this class is setting default values for various properties like so:</p> <pre><code>public class MyEntity: TableServiceEntry { public MyEntity() : MyEntity("invalid", "invalid") {} public MyEntity(string f1, string f2) { Field1 = f1; Field2 = f2; } public string Field1 { get; set; } public string Field2 { get; set; } } </code></pre> <p>I tested this class locally (on the emulator) by constructing the following entity:</p> <pre><code>MyEntity e = new MyEntity("hello", null); </code></pre> <p>I uploaded the entity and then retrieved it locally and the two fields were set to "hello" and null, respectively, as expected. </p> <p>However, when I uploaded the same entity to the Azure cloud, what I received back was "hello" and "invalid", respectively, for the two properties. </p> <p>My code that saves the entity is below:</p> <pre><code>public class MyTable : TableServiceContext { ... public void AddEntry(MyEntity e) { this.AddObject("MyTable", e); this.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate); } } </code></pre> <p>I was able to fix this by making the default constructor take no arguments, but now I feel like I have a fundamental misunderstanding of how table storage works. Is it true that when you specify defaults for properties of a TableServiceEntry, those become the defaults for each row in the table in the cloud but not in the emulator (i.e. cloud vs. SQL Express)? If so, why can't I override those defaults with <code>null</code> in the cloud? Is there any documentation that explains how default constructors and <code>null</code>s work in Azure table storage?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload