c# - Linq - Linq 表达式不同的上下文错误
问题描述
我有 3 张桌子
- ERPEntry
- ERPEntryType
- ERPApp
我正在尝试使用以下查询从这 3 个表中获取数据,但出现错误:
指定的 linq 表达式包含对与不同上下文关联的查询的引用
var erpEntryInfo = (from s in ERPDB.ERPEntrys
JOIN t in ERPDB.ERPEntryTypes
on s.EntryTypeID equals t.EntryTypeID
join a in APPDB.ERPApps
on s.AppId equals a.AppId
where s.UserIDAdded == '250176'
select new ERPInfo
{
EntryId = s.EntryID,
EntryType = t.EntryTypeName,
ERPApp = a.ApplicationName,
DateAdded = s.DateAdded
}).OrderByDescending(d => d.DateAdded).Take(10).ToList();
我根据错误进行了搜索,并尝试将上述查询拆分为 2,如下所示。
var res = (from s in ERPDB.ERPEntrys
join t in ERPDB.ERPEntryTypes
on s.EntryTypeID equals t.EntryTypeID
where s.UserIDAdded == '250176'
select new {s.EntryTypeID, s.DateAdded, t.EntryTypeName, s.AppID }).OrderByDescending(d => d.DateAdded).Take(10).ToArray();
var y = (from a in APPDB.ERPApps
join b in res on a.AppId equals //??//
select new ERPInfo
{
EntryId = b.EntryID,
EntryType = b.EntryTypeName,
ERPApp = a.ApplicationName,
DateAdded = b.DateAdded
}).ToList();
我在上面的查询中遇到了访问 AppId 的问题,我进入了结果 res..我在上面的代码中用 //??// 评论
我能得到任何帮助吗?
解决方案
推荐阅读
- emacs - org-plot 输出在 emacs-29 中的什么位置?
- hl7-fhir - 如何从 hapi fhir 客户端调用 partition-management-create-partition
- r - 有什么方法可以检测数据框中的“错误”度量吗?
- python - Python 3.9 中的 TCP 聊天 - ConnectionAbortedError: [WinError 10053]
- python - 在循环内更新字典
- postgresql - 使用 IN 转换 PostgreSQL JSONB 列结果以用于条件
- r - strsplit 返回带有反斜杠和引号的嵌套列表 \"
- python - 如何从列表中随机选择一个元素,然后使用一个简单的公式来更改这个值(并在 for 循环中进行)?
- quarkus - oidc-client:grant.type=password 不支持其他授权选项
- database - 运输区 - 表费率 - 不保存信息