枚举类型没有被映射到数据库表
我使用的是EF 5.0 code首先,在.NET 4库。尝试设置类成员是一个枚举
类型,但它不会被保存到数据库,并在EF正在创建基于数据库没有发生运行时异常在code。
I'm using EF 5.0 Code First, in a .NET 4 library. Trying to set a class member to be of an Enum
type, but it doesn't get persisted to the database, and no runtime exception occurs when EF is creating the database based on the code.
当然,当我尝试针对该ENUM查询:
Of course, when I try to query against that Enum:
var departments = db.Departments
.Where(dep => dep.Name == DepartmentNames.English);
我得到一个异常的说法:
I get an exception saying:
The specified type member 'Name' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
我使用的枚举使用微软的例子:的http:// MSDN。 microsoft.com/en-us/data/hh859576.aspx
不支持枚举成员吗?请问EF 5.0不同,在某种程度上,当一个.NET 4 environemt主持比当一个.NET托管的5呢?
Are Enum members not supported yet? Does EF 5.0 differs somehow when hosted by a .NET 4 environemt than when hosted by a .NET 5 one?
在这里首先在EF 5组件,住在.NET框架4.5(System.Data.Entity.dll)推出枚举。如果您使用的是EF5但目标.NET Framework 4的存在对枚举不支持,因为它们不支持System.Data.Entity.dll是.NET Framework的一部分4。所以,是的EF5在.NET Framework 4的是比较EF5在.NET框架4.5时,范围下来。当你攻击其他的一些功能可用的.NET Framework 4.5,但仅当你面向.NET Framework 4的是空间类型,表值函数,strored过程中返回多个结果和一对夫妇更。另一种方法是移动到EF6(Alpha版附带了几个星期前),它不依赖于System.Data.Entity.dll,因此支持在EF5运双方的.NET Framework 4.5和.NET Framework 4再加上一些的所有功能更多(在.NET框架4.5例如异步)。 EF6是微软的一个开源项目,你可以在这里找到所有的细节: HTTP://entityframework.$c$ cplex.com/
Enums where first introduced in EF 5 components that live in .NET Framework 4.5 (System.Data.Entity.dll). If you are using EF5 but target .NET Framework 4 there is no support for enums since they are not supported by the System.Data.Entity.dll that is part of .NET Framework 4. So, yes EF5 on .NET Framework 4 is scoped down when comparing to EF5 on .NET Framework 4.5. Some other features that are available when you target .NET Framework 4.5 but not available when you target .NET Framework 4 are spatial types, Table Valued Functions, strored procedures returning multiple resultsets and a couple more. An alternative is to move to EF6 (Alpha release shipped a few weeks ago) which does not depend on System.Data.Entity.dll and therefore supports all features that shipped in EF5 on both .NET Framework 4.5 and .NET Framework 4 plus some more (e.g. async on .NET Framework 4.5). EF6 is an open source project from Microsoft and you can find all details here: http://entityframework.codeplex.com/