0

LINQ コードがあり、次のエラーが表示されます。System.ServiceModel.FaultException: The type 'ObjectMgmt' is not supported in aggregation operations.

(from cinnost in edc.CinnostSOPs
 where cinnost.LegislativneVyznamna == true &&
       cinnost.ObjektId == objektid
 select (from o in edc.PlanRealizaces
         where o.CinnostSOPIdSOP == cinnost.IdSOP &&
               o.DatumPlatnosti <= DateTime.Now &&
               o.Provest == true &&
               o.DatumProvedeni == null
         orderby o.DatumPlatnosti descending
         select new ObjectMgmt
         {
             Datum = (DateTime.Now.Date - o.DatumPlatnosti.Value).TotalDays
         }).Max(m => m)).ToList<ObjectMgmt>();
4

3 に答える 3

1

表示されるコンパイラ エラーObjectMgmtは、集計のソースとして使用できないことを示しています。これは、型が implementationMaxを必要とするために発生します。ObjectMgmtIComparable

クエリをフォーマットして読みやすくした後、最大値を持つObjectMgmtインスタンスを見つけたいようです。Datum

で値を降順で並べ替えたので、値が昇順でインスタンスが並べ替えられているDatumPlatnostiことがわかります。したがって、集計はまったく必要ありません。シーケンスの最後の要素を取得するだけです (ただし、昇順で並べてから最初の要素を取得します)。ObjectMgmtDatum

(from cinnost in edc.CinnostSOPs
 where cinnost.LegislativneVyznamna == true &&
       cinnost.ObjektId == objektid
 select (from o in edc.PlanRealizaces
         where o.CinnostSOPIdSOP == cinnost.IdSOP &&
               o.DatumPlatnosti <= DateTime.Now &&
               o.Provest == true &&
               o.DatumProvedeni == null
         orderby o.DatumPlatnosti
         select new ObjectMgmt
         {
             Datum = (DateTime.Now.Date - o.DatumPlatnosti.Value).TotalDays
         }).First()).ToList<ObjectMgmt>();
于 2013-04-13T23:23:57.323 に答える
0

Because your ObjectMgmt objects have only one property filled by query: Datum, change your Max call to get max of Datum, not the ObjectMgmt itself:

(from cinnost in edc.CinnostSOPs
 where cinnost.LegislativneVyznamna == true &&
       cinnost.ObjektId == objektid
 select (from o in edc.PlanRealizaces
         where o.CinnostSOPIdSOP == cinnost.IdSOP &&
               o.DatumPlatnosti <= DateTime.Now &&
               o.Provest == true &&
               o.DatumProvedeni == null
         orderby o.DatumPlatnosti descending
         select new ObjectMgmt
         {
             Datum = (DateTime.Now.Date - o.DatumPlatnosti.Value).TotalDays
         }).Max(m => m.Datum)).ToList<ObjectMgmt>();
于 2013-04-14T07:27:56.007 に答える