【问题标题】:Entity Framework is not working in class library project实体框架在类库项目中不起作用
【发布时间】:2015-12-21 03:51:02
【问题描述】:

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

向实体框架 dll 添加 ref 后,我无法在类属性上使用“必需”等数据注释属性。

请告诉我解决方法是什么?

【问题讨论】:

    标签: asp.net-mvc entity-framework-4.1


    【解决方案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;}
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 2017-05-09
      • 1970-01-01
      相关资源
      最近更新 更多