Znajdź max i min DateTime w grupie Linq
Próbuję znaleźć maks. I minDateTime
s z importu CSV.
Mam to, aby zaimportować dane z tempDataTable
:
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
};
Co działa dobrze. Następnie chcę pogrupować dane i pokazać czas rozpoczęcia i czas zakończenia, który jest min / max odpowiednich pól.
Do tej pory mam to:
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
};
Z takim myśleniemg.Min
ig.Max
dałby mi najniższą i najwyższąDateTime
dla każdego grafiku (pogrupowanego według indeksu)
Nie działa to jednak ... Co jest najlepszym sposobem na znalezienie najwyższej i najniższej wartości DateTimes w grupie?