【问题标题】:LINQ Subquery in Where Clause returning error in LINQPadWhere 子句中的 LINQ 子查询在 LINQPad 中返回错误
【发布时间】: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


【解决方案1】:

解决了。错误线路的正确导航路线是:

.Where(e => innerquery.Any(a => a.com_id == e.customer.application.com_id)) // exception at this line
.Where(e => innerquery.Any(a => a.fnd_id == e.customer.application.fnd_id))

错误是由于e.advice.application

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 2010-10-28
    • 1970-01-01
    • 2018-08-14
    • 1970-01-01
    • 2016-10-06
    相关资源
    最近更新 更多