Sandillio Sandy
Sandillio Sandy

Reputation: 29

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'

I wanted to get sum of specific columns so I have used the group by in linq, but seems like I must getting the error in join. The datatypes of the fields are the same. This is not the original query but a made up one for Stack Overflow posting.

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
}

Upvotes: 0

Views: 286

Answers (1)

Rawling
Rawling

Reputation: 50184

You need

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

to be

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

At the moment your Join selectors are

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

and the properties of the second are IEnumerables of the types of the properties of the first, rather than matching the types.

(TRANTYPE should probably be the same.)

Upvotes: 1

Related Questions