I would like to pick the latest DataItem record for each QuestionID that is in the ‘ids‘ array.
Because I cannot use .Value within LINQ I have converted the ids to Nullable. However I now get an ‘Object must implement IConvertible’
Table:DataItem
------------------------------------
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);
1 Answer