2016-09-20 98 views
0

我使用Visual Studio 2015年和Entity Framework版本6.0.0.0(代码第一次),我创建了一个类为:类型或命名空间名称“ForeignKey的”无法找到

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; } 
    } 
} 

现在我正在此错误:

Error CS0246 The type or namespace name 'ForeignKey' could not be found (are you missing a using directive or an assembly reference?)

我已经参考: Refrances

我怎样才能解决呢?

+0

不应该'[关键]'是'[Key]'? –

+0

坦克[键]是[键]工作,但我仍然有错误“错误CS0246无法找到类型或命名空间名'ForeignKey'(你是否缺少使用指令或程序集引用?)” – NorouziFar

回答

0

1)为了解决这个问题检查您的参考版本:

System.ComponentModel.DataAnnotations

2)[key][Key]

希望这有助于其他人

+0

not worked!看看我的代码的顶部“使用System.ComponentModel.DataAnnotations.Schema;” – NorouziFar

+0

@NorouziFar试试这个:其他人可能会遇到这种情况:如果您升级后被迫降级,请执行以下操作。 (a)从Nuget卸载EF(b)设置目标.NET框架(c)重新安装EF(d)确保添加了.Schema引用。 – praguan

+1

我发现我的问题:我用System.ComponentModel.DataAnnotations版本5,但我应该使用System.ComponentModel.DataAnnotations版本4 – NorouziFar

1

添加对System.ComponentModel.DataAnnotations.Schema的引用。

相关问题