找不到类型或命名空间名称 'ForeignKey'

The type or namespace name 'ForeignKey' could not be found

我正在使用 Visual Studio 2015 和 entity framework 版本 6.0.0.0(代码优先),我创建了一个 class 作为:

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

我该如何解决?

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

1) 要解决它,请检查您的参考版本:

System.ComponentModel.DataAnnotations

2) [key] 应该是 [Key]

希望这对其他人有帮助