TableEntity missing Serializable or DataContract attribute

Dan 31 Reputation points
2020-12-18T18:04:08.823+00:00

Why isn’t the TableEntity class annotated with either the SerializableAttribute or DataContractAttribute? This would be very helpful considering TableEntity needs to be the base class for Table Entities and no derived classes will serialize without the base class serialize Attribute.

Azure Table Storage
Azure Table Storage
An Azure service that stores structured NoSQL data in the cloud.
181 questions
{count} votes

Accepted answer
  1. KalyanChanumolu-MSFT 8,351 Reputation points
    2020-12-22T06:41:31.533+00:00

    Posting as Answer since there is a 1000-character limit on comments

    @Dan I am not able to repro this.
    Here is a simple test I set up using your pseudo code. I am able to serialize without any issues.
    Please let me know if I am missing something here.

    using Microsoft.Azure.Cosmos.Table;  
    using System;  
    using System.ComponentModel;  
    using System.Runtime.Serialization;  
      
    namespace ConsoleApp1  
    {  
        [DataContract]  
        public class ModelBase : TableEntity, INotifyPropertyChanged  
        {  
            // base-shared logic  
      
            public string BaseClassProperty { get; set; }  
      
            public event PropertyChangedEventHandler PropertyChanged;  
        }  
      
        [DataContract]  
        public class User : ModelBase  
        {  
            public string DerivedClassProperty { get; set; }  
        }  
      
        internal class Program  
        {  
            private static void Main(string[] args)  
            {  
                var user = new User  
                {  
                    PartitionKey = Guid.NewGuid().ToString(),  
                    RowKey = Guid.NewGuid().ToString(),  
                    BaseClassProperty = "BaseClassProperty",  
                    DerivedClassProperty = "DerivedClassProperty"  
                };  
      
                var serializedData = System.Text.Json.JsonSerializer.Serialize(user);  
      
                Console.WriteLine(serializedData);  
            }  
        }  
    }  
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.