我有来自两个不同数据上下文的两个表.尽管两个表都来自同一个数据库,但存在两个单独的数据上下文.
I have two tables from two different Data Contexts. Although both tables are from the same database, two separate datacontexts exist.
错误信息:
查询包含对在不同数据上下文中定义的项目的引用.
The query contains references to items defined on a different data context.
我该如何解决这个问题?任何帮助表示赞赏.谢谢.
How can I get around this? Any help is appreciated. Thanks.
如果您的代码执行以下操作:
If your code does something along the lines of:
from a in dc1.TableA
join b in dc2.TableB on a.id equals b.id
select new { a, b }
...只需将其更改为:
...just change it to:
from a in dc1.TableA
join b in dc1.GetTable<TableB>() on a.id equals b.id
select new { a, b }
L2S 数据上下文使用类上的属性,因此如果您在另一个数据上下文上使用 GetTable 而不是表所附加的数据上下文,则只会从类 def 中获取表、列等属性,并像使用它一样使用它它是您在查询中使用的 DC 的一部分...
The L2S datacontext uses the attributes on the class, so if you use GetTable on another datacontext than the one the table is attached to it will just pick up the table, column, etc attributes from the class def and use it as if it was part of the DC you're using in the query...
这篇关于如何内部连接来自不同数据上下文的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!