我正在尝试获取最小日期时间,然后是最大日期时间并比较两者。但是,当我尝试从 LINQ 中提取 DateTime 值时出现以下错误。任何帮助将不胜感激。
此行引发错误:appChartDateStart = Convert.ToDateTime(dateStartType);
艾伦
无法将类型为“WhereSelectEnumerableIterator
2[System.Linq.IGrouping
2 [System.DateTime,LatencyApp.Domain.Models.ChartHist],<>f__AnonymousType2`1[System.DateTime]]”的对象转换为类型“System.IConvertible”。
我的代码:
DateTime appChartDateStart = DateTime.MinValue;
DateTime appChartDateEnd = DateTime.MinValue;
var dateStartType = from row in myRow
group row by row.LoginDateTime_Rounded into g
select new { MinDateTime = g.Min(row => row.LoginDateTime_Rounded) };
var dateEndType = from row in myRow
group row by row.LoginDateTime_Rounded into g
select new { MinDateTime = g.Max(row => row.LoginDateTime_Rounded) };
appChartDateStart = Convert.ToDateTime(dateStartType);
appChartDateEnd = Convert.ToDateTime(dateEndType);
TimeSpan difAppChart = appChartDateEnd - appChartDateStart;