I'd like to k开发者_开发技巧now how to (if possible) associate tables from different databases using entity framework. I have one edmx for my "xyz" database and another for my "abc" I need to associate them using EF. I know how to fix this using FKs, but that's not what I want, I'd like to be able to do that using the visual editor, not adding, by hand, a FK to my DB.
Here's a pratical example of what I'd like to accomplish:
Table User - database: abc
Table Message - database: xyz
I'd like to associate User to Message and vice-versa.
Could anyone help me?
Thanks!
You can query them together with Linq-to-Objects, but not with L2S or L2E.
A context is wrapped around 1 Db-connection, you cannot track/update entites from multiple db's.
A possible workaround is to 'link' to one of the Db's from the other. MS-SQL can do this. To the EF it would appear 1 database.
There is no way to achieve this using the edmx design surface in EF.
You could encapsulate this association within your domain model and provide a distributed transaction across the two EF Contexts. We've implemented the latter with an EF Context "container" class that given an internal collection of contexts uses a TransactionScope when it contains more than one context (this relies on the IUnitOfWork abstraction to work effectively).
精彩评论