title: Mapping object type property to varbinary(MAX) in Entity Framework
body: <p>I have a situation where I have a type with a property of type <code>object</code>, eg.</p>
  
  <pre><code>public class MyType
  {
     public virtual object MyProp{get; get;}
  }
  </code></pre>
  
  <p>This type will have to be:</p>
  
  <ol>
  <li>Saved using <code>Entity Framework</code> to a database, as a <code>byte[]</code> (I have figured the serialization logic)</li>
  <li>Transmitted through WCF (I will use the <code>KnownType</code> attribute)</li>
  </ol>
  
  <p><strong>How do I map my <code>object</code> property ensuring that it is converted it to a byte array for storage?</strong></p>
  
  <p>N.B: The <code>object</code> property will be a value type(non-complex)</p>
  
  <p>I thought of creating a separate type for saving to the database e.g:</p>
  
  <pre><code>public class MyTypeEntity
  {
     public virtual byte[] MyProp{get; get;}
  }
  </code></pre>
  
  <p><strong>How do I convert/translate between the types while still able to define the relationship mappings?</strong></p>
  
  <p><strong>Does this involve some sort of interception on saving?</strong></p>
  
  <p>The best solution I could think of without breaking my back is simply storing the serialized data in the DB.</p>
  
  <p>If there was some form of <code>property covariance</code> 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.</p>