Using an enum as a primary key with EF
<p>Is it possible to use an enum as a primary key for a table? I have something like the following:</p>
<pre><code>public enum SpecialId : uint {}

public class Thing 
{
     public SpecialId Id { get; set; }
}

public class MyContext : DbContext
{
     public DbSet&lt;Thing&gt; Things { get; set; }
}
</code></pre>
<p>But i get the following error on initialisation:</p>
<blockquote>
<p>An unhanded exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll</p>
<p>Additional information: The key component 'Id' is not a declared property on type 'Thing'. Verify that it has not been explicitly excluded from the model and that it is a valid primitive property.</p>
</blockquote>
<p>This does say it needs to be a primitive (an enum is only castable to primitave) but the <a href="http://blogs.msdn.com/b/efdesign/archive/2011/06/29/enumeration-support-in-entity-framework.aspx" rel="nofollow noreferrer">EF post around enums</a> sugguests this is possible</p>
<blockquote>
<p>Enums as keys</p>
<p>In addition, properties of enum types can participate in the definition of primary keys, unique constraints and foreign keys, as well as take part in concurrency control checks, and have declared default values.</p>
</blockquote>
<p><strong>Am I doing something wrong or is this simply not supported?</strong></p>
<p>On a side not I know that I could hack in this functionality using another property with not mapped on it to translate keys to enums. This is <strong>not</strong> the answer I am looking</p>