Entity Framework 在 class 库项目中不工作

Entity Framework is not working in class library project

我使用 .net 4.0 和 Entity fwk-4.1 在 VS2010 Ultimate 中创建了一个 class 库项目。

向 Entity framework dll 添加引用后,我无法在 class 属性上使用 'Required' 等数据注释属性。

请问有什么解决办法吗?

Required 属性在 System.ComponentModel.DataAnnotations 命名空间内定义并且在 System.ComponentModel.DataAnnotations assembly(dll)

中可用

1) 确保添加对 System.ComponentModel.DataAnnotations assembly(dll)

的引用

2) 添加 using 语句以在 class 文件中导入 System.ComponentModel.DataAnnotations 命名空间。

using System.ComponentModel.DataAnnotations;
public class YourModel
{
  [Required]
  public string Name {set;get;}
}