I have an old project that used ADO.NET to access persistent storage. Currently, I want to migrate it to EF (6.1.3, if that matters) in order to support multiple database providers with minimal code duplication.
There is an object that contains a Hashtable property:
public class Record { ... public Hashtable data { get; set; } }
With ADO.NET, BinaryFormatter used to convert this data property to BLOB and vice versa:
using (MemoryStream stream = new MemoryStream()) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, data); result = stream.GetBuffer(); } //---------- using (MemoryStream serializationStream = new MemoryStream((byte[])value)) { BinaryFormatter formatter = new BinaryFormatter(); result = (Hashtable)formatter.Deserialize(serializationStream); }
Now I need to tell EF how it should store and retrieve this property.
What i tried
I could save another property in essence:
public class Record { public byte[] dataRaw { get; set; } [NotMapped] public Hashtable data { get { } set { } } }
But this solution is error prone, and you must follow a special workflow with this property.
PS Actually, this question concerns not only the Hashtable, but also each user class that must be saved and retrieved in a special way.
source share