Check for null entities in EF statement

c# entity-framework-6

Question

I have a statement like this:

AssignedCas AssignedCase in caseList.GroupBy(o => o.CaseBatch.CaseBatchName)
                                    .Select(g => g.First()).ToList()

But at time o.CaseBatch.CaseBatchName can be null, in which case the above statement will not execute.

Is there a way in the above statement to check if CaseBatchName is not null and only then include it.

1
2
10/9/2019 10:13:21 AM

Popular Answer

You should probably just add a where condition in your Linq. Just like this:

AssignedCas AssignedCase in caseList.Where(o => o.CaseBatch.CaseBatchName != null)
                                    .GroupBy(o => o.CaseBatch.CaseBatchName)
                                    .Select(g => g.First()).ToList()
2
10/9/2019 8:50:42 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow