C# – Entity Framework limitation

centity-framework

I was wondering if anyone had the same need and why (if possible).

My problem is: I can't create a model in EF using two tables from different DBs without some weird workarounds. For my scope that is very much necessary.

Did any of you ever needed to do this?
What did you do? And, like me, do you think MS should add this feature?

Thank you all.

Best Answer

I think the general paradigm is that a single EF model goes against a single database. You can always create multiple models in a project. If you need to do joins or in other ways combine the data between the two models, just do it with LINQ to Objects once you get the data into memory.

Alternatively, you can look into technologies which create database-to-database links right within the DBMS. I know that both SQL Server and Oracle have solutions for this; I'm sure other major DMBS products have similar features. Using this, your EF model would only connect to one database, but that first database could have views that use database links to connect to the second database and combine the data. It will almost definitely more efficient to combine the data at the DBMS level versus at the EF level.