I'm playing around with entity framework and code first approach. The scenario is this:
I'm thinking of two ways I can manage addresses:
Address
table with a column for CompanyId
and HouseId
(for companies addresses only CompanyId
will be inserted and for houses both Ids will be inserted.CompanyAddress
and HouseAddress
tables with the only difference between them being the FK for CompanyId
versus HouseId
. How would you do it? Is there any other, better options?
In EF Core you should use Owned Entity Types for this. In EF 6, use a Complex Type. Both allow you to have an Address type in .NET without having an Address table in your database.