c# - Type 'MyClass' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute. Consider marking the base type -
i error message when try serialize entity derives tableentity
:
type 'myclass' cannot inherit type not marked datacontractattribute or serializableattribute. consider marking base type 'microsoft.windowsazure.storage.table.tableentity' datacontractattribute or serializableattribute, or removing them derived type.
the error message pretty clear what's going wrong.
so question is, how can work around datacontractattribute
not being decorated in tableentity
class?
code:
[datacontract] public class myclass : myowntableentity { [datamember] public string name { get; set; } [datamember] public string email { get; set; } }
i need serialize myclass
byte[]
, save table storage.
public class myclassasbytearray : myowntableentity { public byte[] somebytearray { get; set; } }
if has suggestion on how serialize byte[]
, please let me know.
[edit]
i decided create own serializable tableentity
:
[datacontract] public class myowntableentity : itableentity { private tableentity te = new tableentity(); public myowntableentity () { } public myowntableentity (string partitionkey, string rowkey) { this.partitionkey = partitionkey; this.rowkey = rowkey; } public string partitionkey { get; set; } public string rowkey { get; set; } public datetimeoffset timestamp { get; set; } public string etag { get; set; } public virtual void readentity(idictionary<string, entityproperty> properties, operationcontext operationcontext) { te.readentity(properties, operationcontext); } public virtual idictionary<string, entityproperty> writeentity(operationcontext operationcontext) { return te.writeentity(operationcontext); } }
and derive class, fails writing properties of myclass
, myclassasbytearray
storage table. , that's because created new object of tableentity
.
how can forward parameters passed readentity
, writeentity
in myowntableentity
readentity
, writeentity
methods in actual tableentity
class?
microsoft wrote code, i'd prevent reinventing wheel here.
edit see tableentity.cs
went mssql , dropped azure table storage solution. because has many limitations.
Comments
Post a Comment