How to implement typesafe enum pattern in entity framework core rc2
<p>How can I implement the <a href="http://blog.falafel.com/introducing-type-safe-enum-pattern/" rel="noreferrer">typesafe enum pattern</a> in entity framework core rc2?</p>

<pre><code>public class TestStatus
{
    [Column("Id")]
    public int Id { get; private set; }

    [Column("Description")]
    public string Description { get; private set; }

    [Column("LongDescription")]
    public string LongDescription { get; private set; }

    private TestStatus(int id
        , string description
        , string longDescription)
    {
        Id = id;
        Description = description;
        LongDescription = longDescription;
    }

    public TestStatus() { }

    public static readonly TestStatus Active = new TestStatus(1, "Active", "Active Long Description");
    public static readonly TestStatus Pending = new TestStatus(2, "Pending", "Pending Long Description");
    public static readonly TestStatus Cancelled = new TestStatus(3, "Cancelled", "Cancelled Long Description");
}
</code></pre>

<p>The id generation strategy is set in OnModelCreating:</p>

<pre><code>builder.Entity&lt;TestStatus&gt;()
    .Property(s =&gt; s.Id)
    .ValueGeneratedNever();
</code></pre>

<p>This is a simplified example, but the real code was working in rc1.  When upgrading to rc2, I had to add the Column attributes so that the properties would be mapped (I assume this is because of the private setter).  When attempting to assign the typesafe enum value:</p>

<pre><code>var i = new TestItem
{
    Name = "Test Item 2",
    Status = TestStatus.Active
};
_context.Items.Add(i);
_context.SaveChanges();
</code></pre>

<p>I get one of the following errors depending on the use case:</p>

<p>InvalidOperationException: The instance of entity type 'TestStatus' cannot be tracked because another instance of this type with the same key is already being tracked. For new entities consider using an IIdentityGenerator to generate  unique key values.</p>

<p>Or</p>

<p>SqlException: Violation of PRIMARY KEY constraint 'PK_Statuses'. Cannot insert duplicate key in object 'dbo.Statuses'. The duplicate key value is (1). The statement has been terminated.</p>

<p>I understand the error.  EF thinks that I am trying to create a new instance with the same Id.  How can I tell EF that these instances should be considered the same?  I can workaround this by moving away from the typesafe enum pattern.  I would just like to make it work with the pattern if possible.  It was working in rc1.</p>