外国财产中[必需]的不同含义

时间:2017-05-25 14:55:33

标签: c# entity-framework-core

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

1 个答案:

答案 0 :(得分:0)