EF 6 GroupBy NullReferenceException
Posted by: Eugen Khudoliiv
Date: December 23, 2020 05:11AM

After migration from MSSQL to the MySql I faced this issue with some queries.
For example query with GroupBy statement caused NRE:

var finalActivities = from examActivity in activitiesFilteredForReport
examActivity.CreateTime descending
group examActivity by axamActivity.CreateTime into gr
select gr.FirstOrDefault();

But if I write code like this:

var finalActivities = from examActivity in activitiesFilteredForReport
examActivity.CreateTime descending
group examActivity by axamActivity.CreateTime into gr
select gr.FirstOrDefault().Id;

It gives me Ids without any exception.

In this case, I apply some workaround to make code work:

var ids = activitiesFilteredForReport.GroupBy(activity => activity.OrderExamId)
.Select(g => g.FirstOrDefault().Id);

var finalActivities = from examActivity in activitiesFilteredForReport
join id in ids on examActivity.Id equals id
orderby examActivity.CreateTime descending
select examActivity;

But I not sure is it a good solution. Can anyone help me to sort this issue? What I do wrong?

Options: ReplyQuote


Subject
Written By
Posted
EF 6 GroupBy NullReferenceException
December 23, 2020 05:11AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.