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
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
from b in DepositHistories
join a in Contracts on b.CotractID equals a.ID
join c in LearningPackages on a.LearningPackageID equals c.ID
where g.Sum(x => x.Value) < g.Key.COntractValue || g.Sum(x => x.Value) == null || g.Sum(x => x.Value) == 0
ID = g.Key.ID, Value = g.Sum(x => x.Value), ContractValue = g.Key.COntractValue
foreach(var item in result)
public int LearningPackageID
public class DepositHistory
public class LearningPackage