I have an Organization entity and Address entity in a .NET Core 2.1.12 setup. An organization has 0 or 1 PrimaryAddress and 0 or 1 BillingAddress, both of type Address. I'm struggling with multiple different approaches I have tried.
These two links both looked promising, but both are for ICollection<> of an entity (as if there were multiple possible billing addresses rather than 0 or 1), not a single entity, and I can't seem to get past that. I have also tried the [InverseProperty] attribute with no luck.
https://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in-code-first.aspx Entity Framework Code First - two Foreign Keys from same table
One side note thought I had about this was also that the plural of Address is Addresses ("ES" not just an "S") and not sure if that messes with any kind of built in functionality based on naming conventions.
public class Organization : Trackable
{
[Required]
public int OrganizationId { get; set; }
[Required]
[MaxLength(100)]
public string OrganizationName { get; set; }
// other scalar properties
public int PrimaryAddressId { get; set; }
public virtual Address PrimaryAddress { get; set; }
public int BillingAddressId { get; set; }
public virtual Address BillingAddress { get; set; }
}
public class Address : Trackable
{
[Required]
public int AddressId { get; set; }
[Required]
[MaxLength(100)]
public string Street1 { get; set; }
// other scalar properties
}
Can anyone provide some insight into the best way to set this up?
Thanks!