I’m trying to map the following entity and the problem is that EF makes CloseUserID as required even when they are not annotated with Required attribute.
public class UserRegistration {
[Key]
public string RegistrationID { get; set; }
[Required]
public DateTime CreatedAt { get; set; }
public Nullable<DateTime> ClosedAt { get; set; }
[Required]
public int UserID { get; set; }
[Required]
[ForeignKey("UserID")]
public virtual User User { get; set; }
public int CloseUserID { get; set; }
[ForeignKey("CloseUserID")]
public virtual User CloseUser { get; set; }
}
How can I make EF understand that CloseUserID is optional and not required?
Put
This is it. You don’t need to put that FK annotation above the navigation property.