Entity Framework Code First Mapping Foreign Key Using Fluent API
问题 I have the situation where a User can have several addresses. Accordingly, I have an ICollection on my user class. But I also want the user to be able to choose a default address. So I've done the following: public class User { public int Id { get; set; } public int? DefaultAddressId { get; set; } [ForeignKey("DefaultAddressId")] public virtual Address DefaultAddress { get; set; } public virtual ICollection<Address> Addresses { get; set; } //properties were removed for purpose of this post }