I google up hell lot but could not get it completely, here I found little useful info but not to success. Below is my question,
I have below classes and need a way to specify the relation in entity model.
public class User
{
[Key]
public int UserId { get; set; }
public int? HomeAddressId { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
public virtual Address HomeAddress{ get; set; }
}
public class Address
{
[Key]
public int AddressId { get; set; }
public int UserId { get; set; }
public string AddressLine1 { get; set; }
// other properties
public virtual User User { get; set; }
}
Requirement is each User has many addresses and each address is associated with one User(one-to-many). One of the address is Home Address and hence the User has HomeAddres(optional). HomeAddressId is FK (nullable) to Address table. How do I define this relation in entity model code first preferably in Fluent API method?