Search code examples
sql-serverdatabaseforeign-keysone-to-manyef-core-3.1

one to many relationship between 3 or more table


Image Link

How can I make one to many connections between hotel and restaurant and gallery pictures of these two tables?

How do I do this in ef-core?

More details on the photo above


Solution

  • We have no idea bout your real requirement and the architecture. So, this is just a suggestion only to keep relation between image table.Your attached image little bit confused.

    1. You can keep hotel and Restaurant both in one table by using a category [ flag the record as Restaurant or Hotel] . lets call this table as "Organizations" Then you can keep your image table without any issue as in below table.

    enter image description here

    1. If you need to keep separate tables for Hotels and Restaurants as you explained, then you have to add a Type column [img_type] to your Image table to categorize the image. Based on the category selected, you have to insert "hotel id" or "restaurant id" in to the "img_referance" field.

    enter image description here

    Note: Some hotels they have their own restaurants. If you need to manage those "Restaurant" then you have to introduce "Type column" to your "Restaurant" table as well. In that case, create a new field as "hotel id" in the restaurant table. (one hotel can have many restaurants).