我想在2个IQueryable
变量中共享2列。
我有以下两个变量:
var leavingDays = resourcePlanningsInWeek.Where(rp => rp.Project.IsLeave);
var employeeRostersInWeek = employeeRostersExcludedHolidays
.Where(rp => rp.RosterDate >= startDate &&
rp.RosterDate <= endDate);
我想做这样的事情:
leavingDays.RosterHours / employeeRostersInWeek.DeploymentPlanned 其中leavingDays.PlanDate等于employeeRostersInWeek.RosterDate
最后,我想总结所有价值观。
9/9 = 1
9/9 = 1
4,5 / 9 = 0,5
linq查询的结果(Sum all values)= 2,5
答案 0 :(得分:0)
我认为应该这样做:
var result =
(from l in leavingDays
from r in employeeRostersInWeek
where l.PlanDate == r.RosterDate
select l.RosterHours / r.DeploymentPlanned
).Sum();
但是,如果将RosterHours
和DeploymentPlanned
定义为int
并且您希望得到小数结果,则应首先将其中一个转换为小数数据类型,如下所示:< / p>
var result =
(from l in leavingDays
from r in employeeRostersInWeek
where l.PlanDate == r.RosterDate
select Convert.ToDouble(l.RosterHours) / r.DeploymentPlanned
).Sum();