Finde max und min DateTime in der Linq Gruppe

Ich versuche die max und min zu findenDateTimes aus einem CSV-Import.

Ich habe dies, um die Daten aus dem Temp zu importierenDataTable:

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
                    };

Welches funktioniert gut. Ich möchte dann die Daten gruppieren und die Start- und Endzeit anzeigen, die das Minimum / Maximum der jeweiligen Felder ist.

Bisher habe ich das:

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
                                 };

Mit dem Gedanken, dassg.Min undg.Max würde mir das niedrigste und das höchste gebenDateTime für jede Stundenzettel (gruppiert nach Index)

Dies funktioniert jedoch nicht ... Was ist der beste Weg, um den höchsten und niedrigsten Wert von DateTimes innerhalb einer Gruppe zu finden?

Antworten auf die Frage(1)

Ihre Antwort auf die Frage