【发布时间】:2013-09-12 22:05:37
【问题描述】:
我正在尝试从 EF 4.3.1 升级到 EF 5,并且还从 .Net 4 更改为 .Net 4.5。这是一个给我带来麻烦的类的示例:
using System.ComponentModel.DataAnnotations;
public class MyClass
{
[Key, Column(Order = 0)]
public int CompositeKey1Id { get; set; }
[Key, Column(Order = 1)]
public int CompositeKey2Id { get; set; }
}
首先我收到错误Cannot resolve symbol 'Column'。
所以我添加了
using System.ComponentModel.DataAnnotations.Schema;,因为 ColumnAttribute 已移入 Schema 命名空间。现在我收到Ambiguous reference 错误,因为 EntityFramework.dll 和 System.ComponentModel.DataAnnotations.dll 中都存在 ColumnAttribute。
所以我尝试删除 System.ComponentModel.DataAnnotations.dll 作为参考,现在我得到 Cannot resolve symbol 'Key',因为 KeyAttribute 在那个 dll 中,但不在 EntityFramework.dll 中。
除非在 EF5 中不再需要 KeyAttribute,否则我必须降级 到 .Net 4 才能编译此代码。这不可能吧?我在这里错过了什么?
【问题讨论】:
标签: c# .net entity-framework ef-code-first entity-framework-5