找不到Entity Framework 4注释

dav*_*ooh 4 .net c# annotations entity-framework entity-framework-4

我正在尝试使用注释将POCO类映射到我的数据库表.我需要使用Table注释来指定表的名称,但我无法解析Table注释.

注意:我导入了System.Data.Entity命名空间,但它不起作用.

我必须导入哪个命名空间才能使用EF注释?

注1 我的意思是:

[Table("my_table")]
public class MyClass
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

注2:我的实体框架DLL是v4.0.30319

Man*_*ntz 12

您应该导入System.ComponentModel.DataAnnotations名称空间.

编辑.net 4.5和EF 5.0:你应该使用System.ComponentModel.DataAnnotations.Schema.Table属性

  • 我添加了对我的项目的引用,并将`using System.ComponentModel.DataAnnotations`添加到我的类中,但它仍然不起作用... (2认同)