C# 类型或命名空间名称';外键&x27;找不到
我使用的是Visual Studio 2015和实体框架版本6.0.0.0(代码优先),我创建了一个类:C# 类型或命名空间名称';外键&x27;找不到,c#,entity-framework,code-first,C#,Entity Framework,Code First,我使用的是Visual Studio 2015和实体框架版本6.0.0.0(代码优先),我创建了一个类: using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace IRANMVCCore.Domain.Entity { public class UserProperty { [key] [For
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace IRANMVCCore.Domain.Entity
{
public class UserProperty
{
[key]
[ForeignKey("Instructor")]
[Required(ErrorMessage = "error")]
public string Name { get; set; }
[Required(ErrorMessage = "error")]
public string Famil { get; set; }
[Required(ErrorMessage = "error")]
public string City { get; set; }
[Required(ErrorMessage = "error")]
public string Countries { get; set; }
}
}
现在我得到了这个错误:
错误CS0246无法指定类型或命名空间名称“ForeignKey”
找到(是否缺少using指令或程序集引用?)
我有参考资料:
如何解决此问题?同时添加对
System.ComponentModel.DataAnnotations.Schema的引用。同时添加对System.ComponentModel.DataAnnotations.Schema的引用。1)要解决此问题,请检查您的参考版本:
System.ComponentModel.DataAnnotations
2) [key]
应该是[key]
希望这有助于其他人解决此问题检查您的参考版本:
System.ComponentModel.DataAnnotations
2) [key]
应该是[key]
希望这对其他人有所帮助不应该[key]
是[key]
?坦克[key]是[key]的,但我仍然有错误“error CS0246找不到类型或名称空间名称'ForeignKey'(您缺少using指令或程序集引用吗?”“不应该[key]
是[key]
?坦克[key]是[key]已工作,但仍有错误“error CS0246找不到类型或命名空间名称'ForeignKey'(是否缺少using指令或程序集引用?)”未工作!!请看我的代码顶部“using System.ComponentModel.DataAnnotations.Schema;”@NorouziFar尝试一下:其他人可能会遇到这样的问题:如果升级后被迫降级,请执行以下操作。(a) 从Nuget卸载EF(b)设置目标.NET framework(c)重新安装EF(d)确保添加了.Schema引用。我发现了我的问题:我使用了System.ComponentModel.DataAnnotations版本5,但我应该使用System.ComponentModel.DataAnnotations版本4请编辑您的答案我选择了它接受答案无效!!请看我的代码顶部“using System.ComponentModel.DataAnnotations.Schema;”@NorouziFar尝试一下:其他人可能会遇到这样的问题:如果升级后被迫降级,请执行以下操作。(a) 从Nuget卸载EF(b)设置目标.NET framework(c)重新安装EF(d)确保添加了.Schema引用。我发现了我的问题:我使用了System.ComponentModel.DataAnnotations版本5,但我应该使用System.ComponentModel.DataAnnotations版本4请编辑您的答案我选择了它接受答案