在LINQPad中Where子句返回错误的LINQ子查询

时间:2013-08-13 14:57:46

标签: c# .net linq entity-framework linqpad

在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'不包含'application'的定义,也没有扩展方法'application'接受类型为'LINQPad.User.appSancAdvice'的第一个参数'(按F4添加使用指令或汇编参考)

场景背后的简要逻辑是只选择客户

  • 已批准的建议(status_id = 4);和
  • 在具有相同委员会(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

1 个答案:

答案 0 :(得分: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

引起的