可能有人幫我約 「如何選擇一個領域,是不是在Group By子句中的LINQ」選擇一個字段,是不是在集團通過LINQ
var ReportData =
from a in context.Table1
from b in context.Table2
where a.personelID == b.ID
&& a.DateField.Value.Year == 2011
group a by new { a.personelID, b.Name, b.Surname} into grouping
select new
{
// grouping.Key.DateField,
Name= grouping.Key.Name,
Surname= grouping.Key.Surname,
PagaBruto = grouping.Sum(i => i.Bruto)),
};
我不能選擇字段"DateField"
即表1,我不想在Group By
這個字段,因爲我會得到一個錯誤的結果。 感謝!
每個組中有許多'DateField'值,您需要哪一個? – dasblinkenlight 2011-12-28 20:17:19
如果在group by子句中包含「DateField」會給出錯誤的結果,那麼看起來每個分組的元素具有不同的DateField值。在這種情況下,您不希望將哪些值包含在結果序列的元素中。 – phoog 2011-12-28 20:21:17
當你不想在分組中使用DateField時,這意味着可能在一個分組中存在兩個或多個DateField,那麼如何通過兩個或多個DateField來選擇一個分組呢? – 2011-12-28 20:24:13