How to inner join tables from different Data Context?(如何内部连接来自不同数据上下文的表?)
问题描述
我有来自两个不同数据上下文的两个表.尽管两个表都来自同一个数据库,但存在两个单独的数据上下文.
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...
这篇关于如何内部连接来自不同数据上下文的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何内部连接来自不同数据上下文的表?


基础教程推荐
- 使用 SED 在 XML 标签之间提取值 2022-01-01
- 覆盖 Json.Net 中的默认原始类型处理 2022-01-01
- 创建属性设置器委托 2022-01-01
- Page.OnAppearing 中的 Xamarin.Forms Page.DisplayAlert 2022-01-01
- 我什么时候应该使用 GC.SuppressFinalize()? 2022-01-01
- 如何使用OpenXML SDK将Excel转换为CSV? 2022-01-01
- 从 VB6 迁移到 .NET/.NET Core 的最佳策略或工具 2022-01-01
- 当键值未知时反序列化 JSON 2022-01-01
- C# - 如何列出发布到 ASPX 页面的变量名称和值 2022-01-01
- C# - 将浮点数转换为整数...并根据余数更改整数 2022-01-01