未找到System.ComponentModel.DataAnnotations.Schema

Thi*_*pes 11 .net c# data-annotations asp.net-mvc-4

我在Visual Studio 2012中遇到涉及System.ComponentModel.DataAnnotations.Schema命名空间的问题.它告诉我,ForeignKeyAttribute无法解析,过去的解决方案是添加下面注释掉的using语句.VS2012无法像VS2010那样解析Schema名称空间.最近的.Net版本中是否有任何变化会导致此问题?如果是这样,我该如何解决它们?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; // using System.ComponentModel.DataAnnotations.Schema; namespace Data { public class AffiliateUser { [Key, ForeignKey("User")] public int UserId { get; set; } [StringLength(50)] public string AffiliateUserKey { get; set; } public Guid ApiKey { get; set; } public string PasswordHash { get; set; } public bool IsDeleted { get; set; } } }
Run Code Online (Sandbox Code Playgroud)

par*_*mar 18

您确定要定位.NET 4.5 Framework吗?ForeignKeyAttribute仅在.NET 4.5中可用


Iri*_*lho 5

我重新安装了实体框架,它的确有效!