问题
I have two db contexts in my project. One for users based .Net core identity and another for products and orders etc. for a webshop. The scenario is that a user via .Net core identity can log in, add product to shopping cart and complete an order. Therefor a need to have a foreign key from the identity user dbcontext to the other dbcontext containing the orders and product tables. I would like to have the users and the products/orders in two seperate dbcontext. So my question is how to go about this issue? Is it at all a good idé to have two dbcontext or just have everything in one? Does entity framework have support for this buildt in?
Thanks in advance!
回答1:
Its possible to work with two different db context in same project. As per your statement you want to add foreign key in dbcontext but you should just add foreign key in database and scaffold the model everything else will work fine.
Scaffold and create model in your project context as well. Which will help in interacting with your AspNetUser table directly
回答2:
Im going for the following solution: https://stackoverflow.com/a/48624628/432074 There is no need to overcomplicate things with multiple db contexts.
来源:https://stackoverflow.com/questions/58970941/identity-dbcontext-reference-to-another-dbcontext