locked
LINQ across two different DBContext RRS feed

  • Question

  • I am looking for an efficient way to join more than two entities that are residing on different DBContext.

    I understand EF is very efficient if the entities are brought into single database and are within the same DBConext or I use a Linked Server to connect to another database and associate the entities to a single DBContext.

    I wanted to know if there are efficient ways to write LINQ queries across entities from different DB Contexts.

    Wednesday, April 22, 2015 10:57 PM

Answers

  • Hi Arunesan,

    -->I wanted to know if there are efficient ways to write LINQ queries across entities from different DB Contexts.

    No,  EF does not support queries across more than one DB Context. If you have two contexts but work on one database you may want to merge the contexts. Otherwise you need to bring results for both contexts to the client and combine them using Linq To Objects query.  Also note that in your case you are mixing Linq To Object query (because of .ToList() in the IDQ()) with Linq To Entities - this is also not supported since EF does not know how to bring the materialized non-primitive results to the database where the query will be executed.

    If possible, you could submit this feature request: http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions, The Entity Framework product team is listening to user voice there. You can send your idea there and people can vote. If you submit this suggestion, you might post that link here, I will vote it. Thanks for your understanding.

    Best Regards,
    Youjun Tang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Fred Bao Saturday, April 25, 2015 2:36 AM
    • Marked as answer by Arunesan Wednesday, April 29, 2015 12:11 AM
    Thursday, April 23, 2015 9:28 AM