简体   繁体   中英

Entity Framework one-to-one relationship between multiple tables

I have three entities that need to be linked. In my scenario, I have three tables users , stores and accounts .

Both users and stores can have zero or one account and each account should be either for a store or a user (see image below).

I need a one-to-one relationship between user-account and store-account. Since one-to-one relationship force the model to use one key, the user and store Ids might have conflict.

Is there any solution for this in Entity Framework or do I have a flaw in my design?

多个表之间的一对一关系

It would be much easier to use intermediate tables user_account and store_account, that would store only keys. This way you can enforce any logic you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM