1

これを行う方法を見つけようとしていますが、それでもLinqsytaxと混同しています。

私の目的は、empCodeを指定して最大のeffectiveDateを見つけることです。

var x = (from workingResult in this.DataWorkspace.ApplicationData.WorkingResults
         group workingResult by workingResult.EmployeeCode into g
         where g.EmployeeCode == employeeCode
         && (g.EffectiveDate.HasValue
         && g.EffectiveDate.Value.Equals(date))
         select new {EffectiveDate = g.Max(d=>d.EffectiveDate)});

しかし、コンパイラは私にこれを示します

"ソースタイプ'...'のクエリパターンの実装が見つかりませんでした。'GroupBy'が見つかりません。範囲変数'workingResult'のタイプを明示的に指定することを検討してください。"

これはどういう意味ですか?私は本当にあなたの助けが必要です。ありがとうございました。

4

2 に答える 2

1

where g.EmployeeCode == employeeCodeが無効です。はgタイプIEnumerable<IGrouping<_EmployeeCode type_, _Working result type_>>です。次のことを試してください。

var x = from g2 in (from workingResult in this.DataWorkspace.ApplicationData.WorkingResults
                    group workingResult by workingResult.EmployeeCode into g
                    select g)
        select new {EmployeeCode = g2.Select(w => w.EmployeeCode), MaxEffectiveDate = g2.Max(w => w.EffectiveDate)};

各の最大値がx含まれるようになりました。IEnumerable<_EmployeeCode type_, _Effective data type_>EffectiveDateEmployeeCode

于 2013-02-18T09:06:12.030 に答える
1

コードの問題は、グループgを単一の workingResult であるかのように扱っていることです。実際にはそれらのリストです。さらに、の目的はg.EffectiveDate.Value.Equals(date)何ですか?変数dateに一致する発効日が存在しない場合、最大発効日は常に、または何もないという結果になります。date

以下が機能するはずです。

DataWorkspace.ApplicationData.WorkingResults
             .Where(x => x.EmployeeCode == employeeCode)
             .Max(x => x.EffectiveDate);

EffectiveDateこれは、指定された の最大値を返しますemployeeCode

于 2013-02-18T08:41:01.740 に答える