Entity framework .net 4.5外键数据注释c#
Entity framework .net 4.5外键数据注释c#,entity-framework,entity-framework-5,data-annotations,Entity Framework,Entity Framework 5,Data Annotations,[foreign key(“blah”)]在.net 4.5中是否不再受支持?当我导入dataannotations模型时,intellisense告诉我它不存在。反向属性也会发生同样的情况。他们是不是想让我们用fluent api来代替这些操作?对于fluent api和数据注释有什么标准吗 型号: using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; name
[foreign key(“blah”)]
在.net 4.5中是否不再受支持?当我导入dataannotations模型时,intellisense告诉我它不存在。反向属性也会发生同样的情况。他们是不是想让我们用fluent api来代替这些操作?对于fluent api和数据注释有什么标准吗
型号:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace DevCentral.Entities
{
public partial class Category
{
[Key]
public int Id { get; set; }
[MaxLength(75), MinLength(1)]
public string Name { get; set; }
[Required]
public int ClassificationId { get; set; }
[ForeignKey("ClassificationId"), InverseProperty("Categories")]
public virtual Classification Classification { get; set; }
}
}
ForeignKey在.net 4.5中仍然非常活跃,请检查: 项目中可能缺少对System.ComponentModel.DataAnnotations.dll程序集的引用 更新:
正如@mtleising所评论的,从.net 4.5开始,
ForeignKeyAttribute
的名称空间是System.ComponentModel.DataAnnotations.Schema
我肯定包含了它。。我正在使用.Net 4.5和System.ComponentModel.DataAnnotations的4.0版。我有一些DataAnnotation,比如键,最大和最小长度,是必需的,但是ForeignKey不在那里,不在intellisense或任何东西中。。它把我弄丢了。谢谢你的澄清。还有,关于数据注释的约定有什么提示吗?好的,仅供参考,[ForeignKey]注释在System.ComponentModel.DataAnnotations.Schemath中。没错,文档的网址已经暗示了,但我只参考了程序集文件名,抱歉。