EF4.3.1中的MaxLength属性 [英] MaxLength Attribute in EF4.3.1
问题描述
[路径...] \packages\EntityFramework中的$ System code .4.3.1\lib\\\
et40\EntityFramework.dll
和
'c:\Program文件(x86)\Reference Assemblies\Microsoft\\ \\Framework
\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'
现在,我已经阅读了文档。
从Entity Framework 5.0 Beta 1开始,EntityFramework.dll
不包含数据注释的定义。这些定义
被移动到System.ComponentModel.DataAnnotations.dll,并在System.ComponentModel.DataAnnotations.Schema命名空间中定义
。
The type 'System.ComponentModel.DataAnnotations.MaxLengthAttribute'
exists in both
[path...]\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll
and
'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework
\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'
Now, I have read on msdn that its safe to exclude the EntityFramework reference (which was added through the nuget package). However, when I do that, I cant create a DBContext properly as the DbModelBuilder class lives in the EntityFramework dll. Also, some other critical classes are missing when I remove the EntityFramework refference so this is old and irrelevant solution now.
Update (disambiguation): Both System.ComponentModel.DataAnnotations.dll
and EntityFramework.dll
include System.ComponentModel.DataAnnotations.MaxLengthAttribute
. The problem is that each dll also includes other classes that are critical to EF code-first design. For example:
EntityFramework.dll:
- System.Data.Entity.DbModelBuilder
System.ComponentModel.DataAnnotations.dll:
- System.ComponentModel.DataAnnotations.RegularExpressionAttribute
Add this statement to top of your class
using System.ComponentModel.DataAnnotations;
System.ComponentModel.DataAnnotations
namespace is distibuted across the EntityFramework.dll
and System.ComponontModel.DataAnnotations.dll
. So you need to add a reference to both of that in your project to make use of DataAnnotations.
The MaxLenth attribute is present in EntityFramework.dll
. So make sure you have that reference to that dll present in your project references section.
EDIT : As of .NET framework 4.5, this namespace is moved to the System.ComponentModel.DataAnnotations.dll
. So If you use .NET Framework 4.5 with Entity Framework 4.3.1 or less, You will run in to this conflict. The solution is to switch to Entity framework 1.50 beta 1/ 2 release if you want to stick with .NET 4.5 or downgrade to .NET 4 to use EntityFramework 4.3.1.
From the msdn documentations.
Starting with Entity Framework 5.0 Beta 1, the EntityFramework.dll does not contain definitions for data annotations. These definitions were moved to System.ComponentModel.DataAnnotations.dll and are defined in the System.ComponentModel.DataAnnotations.Schema namespace.
这篇关于EF4.3.1中的MaxLength属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!