Addresses database schema for multiple entities

ⅰ亾dé卋堺 提交于 2021-01-29 19:53:22

问题


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 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.
  • Have a 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?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!