Entity Framework with MySql: Map System.Guid to VARCHAR(40)
<p>I am using Entity Framework 6 code first to connect to a MySql database. I do not own the database. I <strong>cannot</strong> change the database schema. I also cannot change to another flavor of Entity Framework (model or database first). </p>

<p>I'm having trouble mapping my POCO object to a particular table</p>

<p>The table is as follows: </p>

<pre><code>CREATE TABLE 'my_table' (
   'id' VARCHAR(40) NOT NULL,
   'name' VARCHAR(200),
   Primary Key ('id')
)
</code></pre>

<p>I know for a fact that the 'id' column will always be a Guid. Therefore I have created my POCO class as follows:</p>

<pre><code>public class MyTable
{
   public Guid Id { get; set;}
   public string Name { get; set;}
}
</code></pre>

<p>From my understanding EF for MySql will only map VARCHAR columns to string fields in your POCO. Is there any way I can tell entity framework that the 'id' column should be converted from a VARCHAR(40) to a Guid?</p>

<p>I was thinking of accepting that I could not map to a Guid. I'd just map to a string and create a custom getter method:</p>

<pre><code>public class MyTable
{
   public string Id { get; set;}
   public string Name { get; set;}

   public Guid GetId()
   {
       Guid id;
       if (Guid.TryParse(this.Id, out id))
            return id;
       else
            return new Guid();
   }
} 
</code></pre>

<p>Please help an EF newb out. Thanks</p>