项目从原来的.NET Framework4.0 升级到 .NET Framework4.5 编译报错。

查找原因是:

Entity Framework 与 .net4.5 的 System.ComponentModel.DataAnnotations 都有 System.ComponentModel.DataAnnotations.Schema 命名空间。并且都有一些相同的 特性(Attribute), 如:ForeignKeyAttribute, NotMappedAttribute 等。当项目同时引用了 EntityFramework.dll 与 System.ComponentModel.Composition.dll ,你将不能正常使用上面提到的特性。

解决方案:

使用别名,给这两个dll 加一个不同的根。

  • 引用dll, 默认的别名都是 global

  • 将 EntityFramework.dll 的别名改为 EF

  • namespace区域写入 extern alias EF;(原文中写的是在 类的using 区域写入 extern alias EF 我试下了不行,改成namespace区域)

  • *using EF::System.ComponentModel.DataAnnotations.Schema 引用别名加命名空间

参考:

http://blog.csdn.net/lichxi1002/article/details/46986787

System.ComponentModel.DataAnnotations 冲突的更多相关文章

  1. System.ComponentModel.DataAnnotations.Schema 冲突

    System.ComponentModel.DataAnnotations.Schema 冲突 Entity Framework 与 .net4.5 的 System.ComponentModel.D ...

  2. 解决EntityFramework与System.ComponentModel.DataAnnotations命名冲突

    比如,定义entity时指定一个外键, [ForeignKey("CustomerID")] public Customer Customer { get; set; } 编译时报 ...

  3. 对System.ComponentModel.DataAnnotations 的学习应用

    摘要 你还在为了验证一个Class对象中很多数据的有效性而写很多If条件判断吗?我也同样遇到这种问题,不过,最近学了一项新的方法,让我不在写很多if条件做判断,通过给属性标注特性来验证数据规则,从此再 ...

  4. System.ComponentModel.DataAnnotations.Schema.TableAttribute 同时存在于EntityFramework.dll和System.ComponentModel.DataAnnotations.dll中

    Entity Framework 与 .net4.5 的 System.ComponentModel.DataAnnotations 都有 System.ComponentModel.DataAnno ...

  5. System.ComponentModel.DataAnnotations 命名空间和RequiredAttribute 类

    System.ComponentModel.DataAnnotations 命名空间提供定义 ASP.NET MVC 和 ASP.NET 数据控件的类的特性. RequiredAttribute 指定 ...

  6. 使用System.ComponentModel.DataAnnotations验证字段数据正确性

    在.NET MVC 中,当页面提交model到Action的时候,自动填充ModelState.使用ModelState.IsValid进行方便快捷的数据验证,其验证也是调用命名空间System.Co ...

  7. C# 特性 System.ComponentModel 命名空间属性方法大全,System.ComponentModel 命名空间的特性

    目录: System.ComponentModel 特性命名空间与常用类 System.ComponentModel.DataAnnotations ComponentModel - Classes ...

  8. “CreateRiaClientFilesTask”任务意外失败。 未能加载文件程序集“System.ComponentModel.DataAnnot...

    错误  77  “CreateRiaClientFilesTask”任务意外失败.  System.Web.HttpException (0x80004005): 未能加载文件或程序集“System. ...

  9. 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。

    本地win7 本地正常,服务器win2008r2,服务器报错! 异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问. 拒绝访问. 说明: 执行当前 W ...

随机推荐

  1. MD5加密Demo

    package com.util; import java.security.MessageDigest; public class MD5 { public final static String ...

  2. (转)Eclipse快捷键 10个最有用的快捷键

    1 Eclipse中10个最有用的快捷键组合 一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合.通过这些组合可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升. 1 ...

  3. (转)SQL Server基础之存储过程(清晰使用)

    阅读目录 一:存储过程概述 二:存储过程分类 三:创建存储过程 1.创建无参存储过程 2.修改存储过程 3.删除存储过程 4.重命名存储过程 5.创建带参数的存储过程   简单来说,存储过程就是一条或 ...

  4. CocoaPods私有库管理

    简介: 前一篇文章已经介绍过如果安装使用CocoaPods,下面将要介绍如果通过CocoaPods和git来维护我们私有的库. 个人或公司在开发过程中,会积累很多可以复用的代码包,有些我们不想开源,又 ...

  5. kibana 常用查询方法

    下面直接通过实例演示常用的搜索方法 转义特殊字符 + - && || ! () {} [] ^" ~ * ? : \ 注意:以上字符当作值搜索的时候需要用 \ 转义 1.在任 ...

  6. python函数(5):迭代器和生成器

    迭代器和生成器是函数中的一大重点,务必掌握,何为迭代?何为迭代器? 预习: 处理文件,用户指定要查找的文件和内容,将文件中包含要查找内容的每一行都输出到屏幕 一.迭代器 for i in 50: pr ...

  7. CSS实现横列布局的方法总结

    一.使用float实现横列布局的方法 如下面所示:DIV1和DIV2都可以选择向左或者向右浮动50%来实现展示在同一行 div1 div2 实现下面图片中布局的css样式如下: 分析: 1.第一行第一 ...

  8. HDU6055 Regular polygon(计算几何)

    Description On a two-dimensional plane, give you n integer points. Your task is to figure out how ma ...

  9. hdu--1013--Digital Roots(字符串)

    Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  10. 广搜:codevs-3344(初步bfs)

    一道典型的迷宫问题 小刚在迷宫内,他需要从A点出发,按顺序经过B,C,D--,到达最后一个点,再回到A点.迷宫内有些障碍,问至少走几步. 输入描述 Input Description 第一行有三个数n ...