【发布时间】:2013-08-19 14:45:27
【问题描述】:
在 LINQPad 中执行以下查询时:
var innerquery = Bills.Where(e => e.id == 15);
var entity = Customer
.Join(applications, cust => cust.cust_id, app => app.cust_id,
(cust, app) => new { Customer = cust, application = app })
.Join(advices, cust => cust.application.app_id, sa => sa.app_id,
(cust, sa) => new { Customer = cust, advice = sa })
.Where(x => x.advice.status_id == 4)
.Where(e => innerquery.Any(a => a.com_id == e.advice.application.com_id)) // exception at this line
.Where(e => innerquery.Any(a => a.fnd_id == e.advice.application.fnd_id))
.Select(x => x.Customer.Customer.cust_id);
entity.Dump();
它在 LINQPad 中以异常结束:
“LINQPad.User.appSancAdvice”不包含“应用程序”的定义,并且找不到接受“LINQPad.User.appSancAdvice”类型的第一个参数的扩展方法“应用程序”(按 F4 添加using 指令或程序集引用)
场景背后的简要逻辑是只选择客户
- 已获得批准的建议 (status_id=4);和
- 在申请表中具有与特定法案 (innerquery) 相同的委员会 (com_id) 和基金 (fnd_id) 记录
-
customer实体与application相关
-
application实体与advice相关
- 但是,
application实体与bill无关
更新
(table structure)
客户
cust_id
应用程序
app_id
cust_id
com_id
fnd_id
建议
app_id
status_id
账单
bill_id
com_id
fnd_id
【问题讨论】:
-
可能有助于在这里查看底层表结构。
-
@Moo-Juice 请参阅上面的更新。
-
还有 - LinQPad 的“SQL”结果在生成的 SQL 中显示什么?
-
@Moo-Juice 以错误结束,它不显示生成的 T-SQL。
-
它解决了。那条线上的正确格式应该是
.Where(e => innerquery.Any(a => a.com_id == e.customer.application.com_id))
标签: c# .net linq entity-framework linqpad