考慮以下幾點:如何過濾一個基於另一個LINQ查詢的結果?
DP_DatabaseTableAdapters.EmployeeTableAdapter employeetableAdapter = new DP_DatabaseTableAdapters.EmployeeTableAdapter();
DP_Database.EmployeeDataTable employeeTable = employeetableAdapter.GetData();
var leadEmployees = from e in employeeTable
where e.IsLead == true
select e;
DP_DatabaseTableAdapters.LaborTicketTableAdapter tableAdapter = new DP_DatabaseTableAdapters.LaborTicketTableAdapter();
DP_Database.LaborTicketDataTable table = tableAdapter.GetDataByDate(date.ToString("MM/dd/yyyy"));
var totHours = from l in table
join e in leadEmployees on l.EmployeeID equals e.EmployeeID
group l by l.EmployeeID into g
orderby g.Key
select new
{
EmployeeID = g.Key,
HoursWorked = g.Sum(s => s.HoursWorked)
};
總工時正確篩選的基礎誰擁有IsLead位設置爲true人leadEmployee名單上的結果。
我想知道如何使用where子句做到這一點,我已經attempd使用leadEmployees.Contanis不過需要一個整體EmployeeRow ...
我怎麼能添加什麼看起來是一個組成部分IN子句到where過濾器來替換連接?
var totHours = from l in table
where ??????
group l by l.EmployeeID into g
orderby g.Key
select new
{
EmployeeID = g.Key,
HoursWorked = g.Sum(s => s.HoursWorked)
};
這樣,這將您的where子句需要專門評價? – Firoso 2011-06-08 18:16:47
與您的主要問題無關,但您可以簡化收集領導僱員的行:var leadEmployees = employeeTable.Where(e => e.IsLead);' – 2011-06-08 19:25:17