I have a situation where I have a type with a property of type object
, eg.
public class MyType
{
public virtual object MyProp{get; get;}
}
This type will have to be:
- Saved using
Entity Framework
to a database, as abyte[]
(I have figured the serialization logic) - Transmitted through WCF (I will use the
KnownType
attribute)
How do I map my object
property ensuring that it is converted it to a byte array for storage?
N.B: The object
property will be a value type(non-complex)
I thought of creating a separate type for saving to the database e.g:
public class MyTypeEntity
{
public virtual byte[] MyProp{get; get;}
}
How do I convert/translate between the types while still able to define the relationship mappings?
Does this involve some sort of interception on saving?
The best solution I could think of without breaking my back is simply storing the serialized data in the DB.
If there was some form of property covariance
in C#, maybe this would've worked easier. As far as I know, it does not exist.
If there is an elegant alternative that I can use, I would appreciate your insight.