5

DateTimeCSVインポートから最大値と最小値を見つけようとしています。

私は臨時雇用者からデータをインポートするためにこれを持っていますDataTable

var tsHead = from h in dt.AsEnumerable()
         select new
                    {
                        Index = h.Field<string>("INDEX"),
                        TimeSheetCategory = h.Field<string>("FN"),
                        Date = DdateConvert(h.Field<string>("Date")),
                        EmployeeNo = h.Field<string>("EMPLOYEE"),
                        Factory = h.Field<string>("FACTORY"),
                        StartTime = DdateConvert(h.Field<string>("START_TIME")), //min
                        FinishTime = DdateConvert(h.Field<string>("FINISH_TIME")), //max
                    };

これは問題なく動作します。次に、データをグループ化し、それぞれのフィールドの最小/最大である開始時間と終了時間を表示します。

これまでのところ私はこれを持っています:

var tsHeadg = from h in tsHead
                      group h by h.Index into g //Pull out the unique indexes
                      let f = g.FirstOrDefault() where f != null
                      select new
                                 {
                                     f.Index,
                                     f.TimeSheetCategory,
                                     f.Date,
                                     f.EmployeeNo,
                                     f.Factory,
                                     g.Min(c => c).StartTime, //Min starttime should be timesheet start time
                                     g.Max(c => c).FinishTime, //Max finishtime should be timesheet finish time
                                 };

各タイムシート(インデックスでグループ化)の最低値と最高値を私に与えるg.Minと考えてg.MaxDateTime

ただし、これは機能しません...グループ内のDateTimesの最高値と最低値を見つける最良の方法は何ですか?

4

1 に答える 1

10

これを使ってみてください

var tsHeadg = 
    (from h in tsHead
     group h by h.Index into g //Pull out the unique indexes
     let f = g.FirstOrDefault() 
     where f != null
     select new
     {
         f.Index,
         f.TimeSheetCategory,
         f.Date,
         f.EmployeeNo,
         f.Factory,
         MinDate = g.Min(c => c.StartTime),
         MaxDate = g.Max(c => c.FinishTime),
     });
于 2013-03-12T17:10:14.440 に答える