【问题标题】:The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'join 子句中的表达式之一的类型不正确。调用“GroupJoin”时类型推断失败
【发布时间】:2014-09-22 14:46:15
【问题描述】:

我想得到特定列的总和,所以我在 linq 中使用了 group by,但似乎我必须在 join 中得到错误。字段的数据类型相同。这不是原始查询,而是为 Stack Overflow 发布而编造的查询。

from T1 in TXPYTRANs
join T11 in ((from p in TXPYTRANs // geting error right here
              group p by new { p.TRANTYPE, p.BILLYR, p.BILLNO } into g
              select new 
              { 
                  TRANAMT = g.Sum(b => b.TRANAMT), 
                  TRANPENALTY = g.Sum(b => b.TRANPENALTY), 
                  TRANINTEREST = g.Sum(b => b.TRANINTEREST),
                  TRANTYPE = g.Select(s => s.TRANTYPE),
                  BillYear = g.Select(s => s.BILLYR),
                  BillNumber = g.Select(s => s.BILLNO)
              }).Take(100))
on new { BYr = T1.BILLYR, BNo = T1.BILLNO }
equals new { BYr = T11.BillYear, BNo = T11.BillNumber } into T12
from T13 in T12
select new
{
    TranType = T13.TRANTYPE,
    TranAmt = T13.TRANAMT,
    TranPenalty = T13.TRANPENALTY,
    TranInterest = T13.TRANINTEREST,
    BillYr = T13.BillYr,
    BillNo = T13.BillNo
}

【问题讨论】:

    标签: c# linq


    【解决方案1】:

    你需要

    BillYear = g.Select(s=>s.BILLYR),
    BillNumber = g.Select(s=>s.BILLNO)
    

    成为

    BillYear = g.Key.BILLYR,
    BillNumber = g.Key.BILLNO
    

    目前你的Join 选择器是

    T1 => new { BYr = T1.BILLYR, BNo = T1.BILLNO }
    T11 => new { BYr = T11.BillYear, BNo = T11.BillNumber }
    

    并且第二个的属性是第一个属性的类型的IEnumerables,而不是匹配类型。

    TRANTYPE 应该是一样的。)

    【讨论】:

      猜你喜欢
      • 2013-01-23
      • 2012-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      • 2021-09-19
      相关资源
      最近更新 更多