What did I miss? I have the following Linq on C#:
var topfive = (from a in _db.ActivityRecords
join b in _db.ActivityRecordProgresses on a.ActivityRecordId equals b.ActivityRecordId into leftjoin
from c in leftjoin.DefaultIfEmpty()
join d in _db.Customers on a.CustomerId equals d.CustomerId
group c by a.CustomerId into grouped
select new {
label = grouped.Key,
datas = grouped.Count()
}
).ToList();
The result is:
{"tfive":[{"label":2,"datas":5},{"label":4,"datas":1},{"label":140,"datas":1}]}
If I swap the a
and b
. The result become:
{"tfive":[{"label":2,"datas":5},{"label":140,"datas":1}]}
It should be 3 records:
`{"tfive":[{"label":2,"datas":5},{"label":4,"datas":1},{"label":140,"datas":1}]}`
The data is different with my sql script:
select COUNT(a.ActivityRecordId) cTotal, c.CustomerName
from ActivityRecord a
left join ActivityRecordProgress b on a.ActivityRecordId = b.ActivityRecordId
inner join Customer c on a.CustomerId = c.CustomerId
group by c.CustomerName
order by cTotal DESC
It should be:
{"tfive":[{"label":CustomerA,"datas":5},{"label":CustomerB,"datas":1},{"label":CustomerC,"datas":1}]}
What did I wrong? Advice please.
Thank you.