【发布时间】:2015-12-21 03:51:02
【问题描述】:
我在 VS2010 Ultimate 中使用 .net 4.0 和 Entity fwk-4.1 创建了一个类库项目。
向实体框架 dll 添加 ref 后,我无法在类属性上使用“必需”等数据注释属性。
请告诉我解决方法是什么?
【问题讨论】:
标签: asp.net-mvc entity-framework-4.1
我在 VS2010 Ultimate 中使用 .net 4.0 和 Entity fwk-4.1 创建了一个类库项目。
向实体框架 dll 添加 ref 后,我无法在类属性上使用“必需”等数据注释属性。
请告诉我解决方法是什么?
【问题讨论】:
标签: asp.net-mvc entity-framework-4.1
Required 属性在System.ComponentModel.DataAnnotations 命名空间中定义,在System.ComponentModel.DataAnnotations 程序集(dll) 中可用
1) 确保添加对System.ComponentModel.DataAnnotationsassembly(dll) 的引用
2) 添加 using 语句以在类文件中导入 System.ComponentModel.DataAnnotations 命名空间。
using System.ComponentModel.DataAnnotations;
public class YourModel
{
[Required]
public string Name {set;get;}
}
【讨论】: