Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ Join statement with possible NULL id?

Tags:

null

linq

I have a LINQ statement where I am joining on an ID field. The problem is that sometimes the ID on the left of the "equals" may be null.
Is there any way to handle this?

like image 459
James P. Wright Avatar asked May 22 '26 18:05

James P. Wright


1 Answers

from x in left
where x.Id != null
join y in right on x.Id equals y.Id into rightMatches
from y2 in rightMatches.DefaultIfEmpty()  //in your comments you said LEFT JOIN
select new {x, y2};
like image 173
Amy B Avatar answered May 25 '26 10:05

Amy B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!