【发布时间】:2012-05-20 02:36:18
【问题描述】:
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'
现在,我已阅读on msdn,它可以安全地排除 EntityFramework 引用(通过 nuget 包添加)。但是,当我这样做时,我无法正确创建 DBContext,因为 DbModelBuilder 类位于 EntityFramework dll 中。此外,当我删除 EntityFramework 引用时,还缺少一些其他关键类,因此这是旧的且不相关的解决方案。
更新(消歧):System.ComponentModel.DataAnnotations.dll 和 EntityFramework.dll 都包含 System.ComponentModel.DataAnnotations.MaxLengthAttribute。问题是每个 dll 还包含对 EF 代码优先设计至关重要的其他类。例如:
EntityFramework.dll:
- System.Data.Entity.DbModelBuilder
System.ComponentModel.DataAnnotations.dll:
- System.ComponentModel.DataAnnotations.RegularExpressionAttribute
【问题讨论】:
标签: asp.net-mvc entity-framework ef-code-first .net-4.5