如何内部连接来自不同数据上下文的表?
- 作者: 可可12263586
- 来源: 51数据库
- 2022-12-13
问题描述
我有来自两个不同数据上下文的两个表.尽管两个表都来自同一个数据库,但存在两个单独的数据上下文.
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...
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
