我有這些表:組通過LINQ不顯示預期的結果
TestPackagejoint(id,testpackageid,jointid)
Joint(id,endid)
我創建基於jointid,id
testpackage
和joint
和關節之間的關節。
我想組基於endid
和testpackageid
,以及endid
或示例性計數的值:
testpackageid endid count
1 2 3
4 2 1
1 3 2
所以我寫這篇文章的查詢
var q = (from i in _ctx.TestPackageJoints
where i.TestPackageId == Id
join joint1 in _ctx.Joints on i.JointId equals joint1.Id
group new {joint1.EndId,i.TestPackageId} by new { i, joint1}
into g1
select new
{
testpackid = g1.Key.i.TestPackageId,
Count = g1.Count(),
endid = g1.Key.joint1.EndId
}).ToList();
但結果: