问题
I'm playing around with entity framework and code first approach. The scenario is this:
- An user can have multiple companies (each company has an address)
- An user can have multiple houses per company (each house has an address)
I'm thinking of two ways I can manage addresses:
- Have an
Addresstable with a column forCompanyIdandHouseId(for companies addresses onlyCompanyIdwill be inserted and for houses both Ids will be inserted. - Have a
CompanyAddressandHouseAddresstables with the only difference between them being the FK forCompanyIdversusHouseId.
How would you do it? Is there any other, better options?
回答1:
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.
来源:https://stackoverflow.com/questions/60017309/addresses-database-schema-for-multiple-entities