title: Entity Framework Core 1.1.0 Data type conversion
body: <p>I have a legacy database that stores user comments (and quite a few other text fields) as <code>blob</code> datatype, which I cannot change. </p>
  
  <p>I am writing a data access layer that will need to always convert the data to a <code>string</code> when it is retrieved from the database, and convert it back to <code>blob</code> when saving.</p>
  
  <p>The EF scaffolding tool generated properties as <code>byte[]</code> datatype for these entities.</p>
  
  <pre><code>public byte[] Comment { get; set; }
  </code></pre>
  
  <p>I noticed that if I simply change the entity property type to <code>string</code> it actually does save the data correctly, but loading the data results in a casting error:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Byte[]' to type 'System.String'.</p>
  </blockquote>
  
  <p><em>(Interestingly, version 1.0.0 did not throw this error, loading and saving worked ok.)</em></p>
  
  <p><strong>My question is...</strong> Is there a way of configuring EF core to automatically convert this data to string when I retrieve it from the database and back to <code>blob</code> when it gets saved back? Or will I need to write a whole bunch of private getters and setters to do this manipulation?</p>