项目从原来的.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. PHPCMS修改域名

    有时候服务器域名解析时,需要修改网站域名,那么在phpcms中,像一些附件地址什么的都需要修改.下面介绍一下怎么系统全面的修改这些地址. 1.在后台管理中心--设置--站点管理--修改,站点域名改为新 ...

  2. SpringMVC原理及非注解配置详解

    1. Spring介绍 Spring MVC是Spring提供的一个强大而灵活的web框架.借助于注解,Spring MVC提供了几乎是POJO的开发模式,使得控制器的开发和测试更加简单. 这些控制器 ...

  3. selenium3.x 踏坑记

    Selenium 3.x 出来也有段时间了,有哪些坑呢? 有好长一段时间没有用selenium了.最近想用来做个web自动化的小工具.根据以往经验,firefox是不需要下载driver的.启动fir ...

  4. Apache FtpServer 实现文件的上传和下载

    1 下载需要的jar包 Ftp服务器实现文件的上传和下载,主要依赖jar包为: 2 搭建ftp服务器 参考Windows 上搭建Apache FtpServer,搭建ftp服务器 3 主要代码 在ec ...

  5. 【AngularJS】学习资料

    1. http://www.cnblogs.com/lcllao/tag/AngularJs/ http://www.ituring.com.cn/article/13474 http://www.a ...

  6. ES6数组扩展

    前面的话 数组是一种基础的JS对象,随着时间推进,JS中的其他部分一直在演进,而直到ES5标准才为数组对象引入一些新方法来简化使用.ES6标准继续改进数组,添加了很多新功能.本文将详细介绍ES6数组扩 ...

  7. PHPsthdy+xdebug

    PHPsthdy下载后查看phpinfo后会发现没有xdebug这一项: 1.phpStudy集成了XDebug扩展,所以不用单独下载XDebug. 2.打开XDebug扩展:右击PHPstudy的图 ...

  8. 6步就能搞出个react网站哈,玩一把!

    1.安装mk-tools命令行工具   $ npm i -g mk-tools   2.创建空website   $ mk website myDemo $ cd myDemo    3.clone应 ...

  9. JavaScript addEventListener 第三个参数

    先看一个完整的演示页面代码. Code <!DOCTYPE html> <html lang="zh-CN"> <head> <meta ...

  10. [补档][JLOI 2017]聪明的燕姿

    [NOI 2008]假面舞会 题目 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 我听见风来自地铁和人海 我排着队拿着爱的号码牌 ...