join子句中某个表达式的类型不正确。调用' GroupJoin'

时间:2014-09-22 14:46:16

标签: c# linq

我想得到特定列的总和所以我在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
}

1 个答案:

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

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

TRANTYPE可能应该是相同的。)