using System.Collections.Generic;
public static void Main()
List<Contract> Contracts = new List<Contract>()
ID = 1, LearningPackageID = 2
ID = 2, LearningPackageID = 4
ID = 3, LearningPackageID = 6
ID = 4, LearningPackageID = 8
List<DepositHistory> DepositHistories = new List<DepositHistory>()
CotractID = 1, Value = 100
CotractID = 2, Value = 50
CotractID = 3, Value = 200
List<LearningPackage> LearningPackages = new List<LearningPackage>()
ID = 2, COntractValue = 100
ID = 4, COntractValue = 200
ID = 6, COntractValue = 300
ID = 8, COntractValue = 400
var Result = Contracts.GroupJoin(DepositHistories, a => a.ID, b => b.CotractID, (a, b) => new
).Join(LearningPackages, a => a.a.LearningPackageID, b => b.ID, (a, b) => new
e.a.a.ID, e.b.COntractValue
ID = k.ID, ContractValue = k.COntractValue, Value = g.Sum(x => x == null ? 0 : x.a.b.Sum(d => d.Value))}
).Where(x => x.Value < x.ContractValue || x.Value == 0).ToList();
foreach (var item in Result)
public int LearningPackageID
public class DepositHistory
public class LearningPackage