Cannot find Entity Framework 4 annotations

穿精又带淫゛_ 提交于 2019-12-23 12:24:54

问题


I'm trying to map a POCO class to a table of my DB using annotation. I need to use Table annotation to specify the name of my table, but I cannot resolve the Table annotation.

Note: I imported System.Data.Entity namespace but It doesn't work.

Which namespace do I have to import to use EF annotations?

NOTE 1 I mean:

[Table("my_table")]
public class MyClass
{
    // ...
}

NOTE 2 My Entity Framework dll is v4.0.30319


回答1:


I need to use the Table annotation

You need to import the System.Data.Linq library, the TableAttribute can be referenced from the System.Data.Linq.Mapping namespace.




回答2:


You should import the System.ComponentModel.DataAnnotations namespace.

edit for .net 4.5 and EF 5.0: you should use System.ComponentModel.DataAnnotations.Schema.Table Attribute




回答3:


using System.ComponentModel;

and

[DisplayName("My friendly table name")]

Are sufficient to make it work with EF 5/6 and .Net 4.5, no need for System.ComponentModel.DataAnnotations namespace nor System.Data.Linq for these versions.



来源:https://stackoverflow.com/questions/13340733/cannot-find-entity-framework-4-annotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!