在Id上使用必填字段的差异是什么
[Required]
public int? UserId {get; set;}
[ForeignKey("UserId")]
public User User {get; set;}
导航属性或
public int? UserId {get; set;}
[Required]
[ForeignKey("UserId")]
public User User {get; set;}
两者:
[Required]
public int? UserId {get; set;}
[Required]
[ForeignKey("UserId")]
public User User {get; set;}
答案 0 :(得分:0)