title: Error, Must specify valid information for parsing in the string, when using EF Core Value Conversion
body: <p>Based on the EF Core docs (<a href="https://docs.microsoft.com/en-us/ef/core/modeling/value-conversions" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/ef/core/modeling/value-conversions</a>), I'm trying to use EF Core's new Value Conversion on an enumeration. I want to save the enumeration as a string in the SQL Database table. </p>
  
  <p>Here's the entity and enumeration. </p>
  
  <pre><code>public enum InputSetType
  {
      TypeA, TypeB
  }
  
  public class MonthlyInputSet
  {
      public int Id { get; set; }
      public InputSetType Type { get; set; }
  }
  </code></pre>
  
  <p>Here is where I configure the MonthlyInputSet Entity: </p>
  
  <pre><code>public class MonthlyInputSetConfiguration : IEntityTypeConfiguration&lt;MonthlyInputSet&gt;
  {
      public void Configure(EntityTypeBuilder&lt;MonthlyInputSet&gt; builder)
      {
          builder.Property(mis =&gt; mis.Type).HasConversion(v =&gt; v.ToString(), v =&gt; (InputSetType)Enum.Parse(typeof(InputSetType), v));
      }
  }
  </code></pre>
  
  <p>So, I try to run a basic query to get this data and it fails. The query is: </p>
  
  <pre><code>var saved = await _context.MonthlyInputSets.Include(mis =&gt; mis.InsertedBy)
                                                       .Include(mis =&gt; mis.UpdatedBy)
                                                       .Include(mis =&gt; mis.MonthlyInputs)
                                                           .ThenInclude(mi =&gt; mi.EmissionsUnit)
                                                       .FirstOrDefaultAsync(mis =&gt; mis.Id == id);
  </code></pre>
  
  <p>But, an error is thrown on the first line of this query that says, "ArgumentException: Must specify valid information for parsing in the string." So my guess is that I have not properly configured the conversion of the string in the table to the enum in C#. </p>
  
  <p>Full raw stack trace: </p>
  
  <p><a href="https://i.stack.imgur.com/4od0i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4od0i.png" alt="enter image description here"></a></p>
  
  <p>I verified that the correct string value is being returned from the database. It is not null and it is not a blank string. The string value returned matches a member of the enum perfectly.  </p>
  
  <pre><code> public void Configure(EntityTypeBuilder&lt;MonthlyInputSet&gt; builder)
      {
          builder.Property(mis =&gt; mis.Type).HasConversion(
              convertToProviderExpression: v =&gt; v.ToString(), 
              convertFromProviderExpression: v =&gt; Troubleshooting(v)
          );
      }
  
      private InputSetType Troubleshooting(string v)
      {
          return (InputSetType)Enum.Parse(typeof(InputSetType), v);
      }
  </code></pre>
  
  <p>these two images show that the text in every row in the database type column is identical to the 2nd member of the enum that is mapped to this field. </p>
  
  <p><a href="https://i.stack.imgur.com/uNcgi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uNcgi.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/6V3Ar.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6V3Ar.png" alt="enter image description here"></a></p>