Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

azure table storage doesn't add new fields

I created a table in an Azure Table Storage and added a few records using my Entity class derived from TableEntity . After this I added two more properties to this class and tried to insert more records, but looks like the new fields are not added to the storage, and only the old fields are written and read. Am I missing something? I have to do something more to change the layout of the table?

like image 401
Luca Morelli Avatar asked Aug 23 '15 19:08

Luca Morelli


Video Answer


2 Answers

thanks for the info but in the end I found that the problem was another. I used Vs to create the properties in the class, and doing this Vs created properties add an internal setter.
Looks like that in this situation The Azure Storage client simply ignore these properties not creating the fields not writing and not reading, giving no errors at all. Removed the internal keyword started to work correctly.

like image 156
Luca Morelli Avatar answered Sep 20 '22 14:09

Luca Morelli


First, I want to make sure that I understand your scenario. You modified the existing entity class by adding two more properties, then added new entities in the table. You were not able to see two newly added properties, but only able to update/retrieve the old properties. If that is the scenario that you are trying to implement, check the following. You should be able to add new properties.

  1. Add new properties in the class that you derived your entity from TableEntity class. Optional1 and Optional2 are new properties that you are trying to add.

     public class CustomerEntity : TableEntity
     {
            public CustomerEntity() { }
            public CustomerEntity(string lastName, string firstName)
            {
                this.PartitionKey = lastName;
                this.RowKey = firstName;
            }
    
            public string Email { get; set; }
            public string CellPhoneNumber { get; set; }
    
            public string Optional1 { get; set; }
            public string Optional2 { get; set; }    
        }
    }
    
  2. Make sure you set Optional1 and Optional2 values. See the sample code below.

    var customer = new CustomerEntity(LastName, FirstName)
    { 
        Email = Email,
        CellPhoneNumber = cellPhoneNumber,
        Optional1 = optional1,
        Optional2 = optional2,
    }
    
    TableOperation insertOperation = TableOperation.Insert(customer);
    TableName.Execute(insertOperation);
    

Note: I have not compiled the above code so there may be typos and etc.

Thanks, Aung

like image 32
Aung Oo - MSFT Avatar answered Sep 17 '22 14:09

Aung Oo - MSFT