问题描述
我有来自两个不同数据上下文的两个表.尽管两个表都来自同一个数据库,但存在两个单独的数据上下文.
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...
这篇关于如何内部连接来自不同数据上下文的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)