maxlength属性在EF4.3.1 [英] MaxLength Attribute in EF4.3.1

查看:272
本文介绍了maxlength属性在EF4.3.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 类型'System.ComponentModel.DataAnnotations.MaxLengthAttribute
 存在于两个 [路径...] \\包\\ EntityFramework.4.3.1 \\ lib目录\\ net40 \\ EntityFramework.dll 和C:\\ Program Files文件(x86)的\\参考大会\\微软\\框架
\\ .NETFramework \\ V4.5 \\ System.ComponentModel.DataAnnotations.dll

现在,我已阅读<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/fab7a591-f790-4064-aeb5-c320eb5057e5\">on MSDN 的其安全排除的EntityFramework参考(其通过的NuGet包添加)。然而,当我这样做,我不能正确创建的DbContext作为DbModelBuilder类家住的EntityFramework DLL。此外,其他一些重要的类丢失,当我删除的EntityFramework REFFERENCE所以这是旧的,不相关的解决方案了。

更新(消歧):两个 System.ComponentModel.DataAnnotations.dll EntityFramework.dll 包含 System.ComponentModel.DataAnnotations.MaxLengthAttribute 。问题是,每个DLL还包括其他类,是EF code-第一个设计的关键。例如:

  EntityFramework.dll:
  - System.Data.Entity.DbModelBuilderSystem.ComponentModel.DataAnnotations.dll:
  - System.ComponentModel.DataAnnotations.RegularEx pressionAttribute


解决方案

这语句添加到类的顶部

 使用System.ComponentModel.DataAnnotations;

System.ComponentModel.DataAnnotations 命名空间横跨 EntityFramework.dll 系统distibuted .ComponontModel.DataAnnotations.dll 。所以,你需要参考您的项目中利用DataAnnotations的同时添加到这一点。

该MaxLenth属性是present在 EntityFramework.dll 。因此,请确保你在你的项目引用部分,提及该DLL present。

编辑:由于.NET框架4.5,此命名空间移动到 System.ComponentModel.DataAnnotations.dll 。所以,如果你使用的.NET Framework 4.5与实体框架4.3.1或更少,您将在运行到这个矛盾。解决的办法是,如果你想继续使用.NET 4.5或降级到.NET 4中使用的EntityFramework 4.3.1切换到实体框架的1.50测试版1月2日发布。

MSDN 单证。


  

与实体框架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.

这篇关于maxlength属性在EF4.3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆