Simulating Cross Context Joins--LINQ/C#

前端 未结 3 587
长发绾君心
长发绾君心 2020-11-28 08:32

Here\'s the issue:

I have 2 data contexts that I would like to do a join on. Now I know that LINQ doesn\'t allow joins from one context to another, and I know that 2

3条回答
  •  迷失自我
    2020-11-28 08:37

    This is the "work around" that we have found...

    We built our tables from the other database out manually and if it is on the same server then we prefixed the table name with:

    ..
    

    if they are on a linked server then you have to prefix it with the server name as well:

    ...
    

    This will allow you to do joins and still return an non executed IQueryable... which is what we wanted. The other 2 ways in involve joining in-memory IEnumerables which means your pull all records for each before doing the join (above) and doing an IQueryable join using a contains method which has limitations...

    Hopefully in the future the DataContext will be built smart enough to know that if the servers are linked then you can do joins between two different ones.

提交回复
热议问题