when will Microsoft's EF6 team add full enum support?
Sample code snippets are below. vs2013, EF6.0.1
Since EF5, presumably EF had support for enum.
There is however a GOTCHA: http://msdn.microsoft.com/en-us/data/hh859576
not all underlying types are supported.
Only: Byte, Int16, Int32, Int64 , or SByte.
imho, Microsoft fails programmers here in at least three ways:
(a) types like ulong are valid and should be supported.
(b) Visual Studio gives zero warning when columns are not created.
(c) one gets to assign to the Poco fields and gets lulled into thinking that her/his code is working.
Yes, testing should reveal the issue, as it did for me, however, i almost missed it because my SQL table has a large number of columns.
at http://msdn.microsoft.com/en-us/data/ee712907, the EF team suggests we should post EF questions here at SO.
Here's the code:
namespace EF6enums
{
public enum Country : long { Canada = 1, England = 2 }
changing "long" to "ulong" breaks the code.
public class EF6Poco
{
public Int32 ID { get; set; }
public String City { get; set; }
public Country CountryEnum { get; set; }
}
We are using Code First:
public class EnumTestContext : System.Data.Entity.DbContext
{
public System.Data.Entity.DbSet<EF6Poco> EF6Pocos { get; set; }
}
Here's the Main method:
class Program
{
static void Main(string[] args)
{
using (var context = new EnumTestContext())
{
context.EF6Pocos.Add(new EF6Poco
{ City = "Wasaga Beach",
CountryEnum = Country.Canada });
context.SaveChanges();
}
Console.WriteLine("Done");
Console.ReadLine();
}
}
} // namespace EF6enums