CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
List<Contract> Contracts = new List<Contract>()
{
new Contract
{
ID = 1, LearningPackageID = 2
}
, new Contract
{
ID = 2, LearningPackageID = 4
}
, new Contract
{
ID = 3, LearningPackageID = 6
}
}
;
List<DepositHistory> DepositHistories = new List<DepositHistory>()
{
new DepositHistory
{
CotractID = 1, Value = 100
}
, new DepositHistory
{
CotractID = 2, Value = 50
}
, new DepositHistory
{
CotractID = 3, Value = 200
}
}
;
List<LearningPackage> LearningPackages = new List<LearningPackage>()
{
new LearningPackage
{
ID = 2, COntractValue = 100
}
, new LearningPackage
{
ID = 4, COntractValue = 200
}
, new LearningPackage
{
ID = 6, COntractValue = 300
}
};
var result =
from b in DepositHistories
join a in Contracts on b.CotractID equals a.ID
join c in LearningPackages on a.LearningPackageID equals c.ID
group b by new
{
a.ID, c.COntractValue
}
into g
where g.Sum(x => x.Value) < g.Key.COntractValue || g.Sum(x => x.Value) == null || g.Sum(x => x.Value) == 0
select new
{
ID = g.Key.ID, Value = g.Sum(x => x.Value), ContractValue = g.Key.COntractValue
};
foreach(var item in result)
{
Console.WriteLine(item);
}
}
}
public class Contract
{
public int ID
{
get;
set;
}
public int LearningPackageID
{
get;
set;
}
}
public class DepositHistory
{
public int CotractID
{
get;
set;
}
public int Value
{
get;
set;
}
}
public class LearningPackage
{
public int ID
{
get;
set;
}
public int COntractValue
{
get;
set;
}
}