未找到System.ComponentModel.DataAnnotations.Schema
我遇到涉及System.ComponentModel.DataAnnotations.Schema命名空间的Visual Studio 2012中的问题。 它告诉我,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; } } }
您确定要定位.NET 4.5 Framework吗? ForeignKeyAttribute仅在.NET 4.5中可用
我重新安装了entity framework,它的工作原理!
您的代码和System.ComponentModel.DataAnnotations.Schema
命名空间是正确的。
所以检查你的参考资料 这个应该在Assembly System.ComponentModel.DataAnnotations.dll, v4.0.0.0
您是否从Fx 4升级了项目?
您可以使用NuGet修复版本。
您可以在项目的“参考”部分中找到该程序集。 单击框架选项卡并搜索Assembly。 这是Microsoft .Net框架的默认程序集。
删除已添加的引用System.ComponentModel.DataAnnotations并再次包含它。
如果仍然无效,请完全卸载entity framework并通过nuget manager重新安装。