1 対 1 の関係を設定しようとしていますが、属性を FK として宣言する際に問題が発生しました。ここに投稿された質問のいくつかを既に検索して読んでいますが、私の問題には対処していません。
public class User
{
[Key]
public int userId {get;set;}
[DisplayName("User Name")]
[Required(ErrorMessage="User name required.")]
public string username {get;set;}
[DisplayName("Password")]
[Required(ErrorMessage="Password required.")]
[MinLength(6)]
public string password {get;set;}
[DisplayName("Email")]
[Required(ErrorMessage="Email required.")]
public string email {get;set;}
public virtual List<RoleDetail> roleDetails { get; set; }
public virtual Customer customer { get; set; }
}
public class Customer
{
[Key]
public int cusomterId { get; set; }
[DisplayName("First Name")]
[Required(ErrorMessage="First name required.")]
public string firstname {get;set;}
[DisplayName("Last Name")]
[Required(ErrorMessage="Last name required.")]
public string lastname {get;set;}
[ForeignKey("userId")]
public int userId {get;set;}
}
[ForeignKey] アノテーションを使用すると、このエラーが発生します。そして私はSystem.ComponentModel.DataAnnotationsを使用しています。また、[キー]も正常に動作します。
The type or namespace name 'ForeignKeyAttribute' could not be
found (are you missing a using directive or an assembly reference?)
ここで何が欠けていますか?