Why doesn't Azure Table Storage save the type name when using ResolveName?

I am trying to control the serialization of Azure table objects as a continuation. How do I get multiple types of objects using a single query in Azure Table Storage? and encountered unexpected behavior (for me).

When retrieving elements, the name is always " <myaccountname>.Pets" no matter what I set when I save the object. Why type name is not saved.

According to MSDN:

DataServiceContext.ResolveType

Gets or sets the function that is used to override the default permission setting used by the client library when receiving objects from the Open Data Protocol (OData) service.

DataServiceContext.ResolveName

Gets or sets a function to override the default permission strategy used by the client library when sending entities to the data service.

And this blog post should not be.

Here is a simple test:

public class Pet : TableServiceEntity { }
    public class Cat : Pet { }
    public class Dog : Pet { }


    public class Test
    { 

        public void RunTest()
        {
            //this.Create();
            this.Read();
        }

        public TableServiceContext GetTableServiceContext()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            tableClient.CreateTableIfNotExist("Pets");

            TableServiceContext serviceContext = tableClient.GetDataServiceContext();

            serviceContext.ResolveName = (entityType) =>
            {
                return entityType.FullName;
            };

            serviceContext.ResolveType = (s) =>
            {
                return Type.GetType(s);
            };

            return serviceContext;
        }

        public void Create()
        {

            var serviceContext = this.GetTableServiceContext();

            // Create entries
            var cat = new Cat() { PartitionKey = "cats", RowKey = "1" };
            serviceContext.AddObject("Pets", cat);

            var dog = new Dog() { PartitionKey = "dogs", RowKey = "1" };
            serviceContext.AddObject("Pets", dog);


            serviceContext.SaveChangesWithRetries();
        }

        public void Read()
        {
            var serviceContext = this.GetTableServiceContext();

            var pets = serviceContext.CreateQuery<Pet>("Pets").AsTableServiceQuery<Pet>().ToArray();

            foreach (var pet in pets)
            {
                Console.WriteLine(pet.GetType());
            }

        }
    }
+3
source share
1 answer

After some digging and discussion, I found that the file_name is never visible on the azure tables (this is schematic). Instead, all public properties are serialized and simply send a payload to the properties of the service.

If you need to determine the type, you will need to store / check the property in the payload. This can be done using object write / write events.

. , , , , .

+1

All Articles