我想为“ ids ”数组中的每个QuestionID选择最新的 DataItem 记录。因为我不能在 LINQ 中使用.Value,所以我已将 id 转换为Nullable。但是我现在得到一个“对象必须实现 IConvertible”
表:数据项
------------------------------------
ID | Guid |
DataItemTimeLocal | DateTime |
QuestionID | Guid? |
------------------------------------
Guid?[] ids = GetAllQuestions().Select(x => (Guid?)x.ID).ToArray();
var latestItems = (from di in DataObjects.DataItems
where di.QuestionID != null && ids.Contains(di.QuestionID)
group di by di.QuestionID into g
select g.OrderByDescending(x => x.DataItemTimeLocal).FirstOrDefault()
).ToDictionary(x => x.QuestionID, y => y);