The below query fails with Null Reference Exception when there are elements in BOMIDs where MatID property is nothing.
I thought the ‘x.MatID isnot Nothing AndAlso’ would prevent the x.MatID.Process part of the where from being executed. There are a couple elements in the BOMIDs collection that where MatID is nothing.
Any thoughts?
From x In BOMIDs _
Group Join y As PurchasedProcess In SpecialProcesses _
On x.MatID.PurchasedProcess Equals y.Name _
Into G = Group _
From z In G.DefaultIfEmpty() _
Where x.MatID IsNot Nothing AndAlso _
x.MatID.Process = ProcessEnum.PurchasedProcess _
Select New With {.Item = x.Item, .Process = z}
AndAlsoisn’t the problem. Move your null check to just before the join to effectively filter out all null occurrences before joining on them.Try this updated query: