比如,定义entity时指定一个外键,
[ForeignKey("CustomerID")] public Customer Customer { get; set; }
编译时报错信息如下:
类型“System.ComponentModel.DataAnnotations.Schema.ForeignKeyAttribute”同时存在于“e:个人Wede框架WedeNetpackagesEntityFramework.5.0.0lib
et40EntityFramework.dll”和“c:Program
Files (x86)Reference
AssembliesMicrosoftFramework.NETFrameworkv4.5System.ComponentModel.DataAnnotations.dll”中
解决方法:
1、引用目录下右键EntityFramework,打开属性页;
2、设置别名,把默认的Global修改为EF;
![](https://img2018.cnblogs.com/blog/322080/201810/322080-20181008134928419-1241818973.jpg)
这样,就不会再提示命名冲突了。但是这时候原来可以正常引用EntityFramework.dll的地方现在都需要重新指定了。如下:
3、在需要引用的文件using最上面,加上extern alias EF;
4、原来的属性前面也要加上EF::,如下图:
![](https://img2018.cnblogs.com/blog/322080/201810/322080-20181008134942039-190457187.jpg)
参考:
https://stackoverflow.com/questions/10841393/cant-compile-c-sharp-project-because-of-some-tuple-error-when-referencing-an-ex/10841652#10841652
http://blog.csdn.net/lichxi1002/article/details/46986787
http://www.mamicode.com/info-detail-1766068.html