Imagine I have 2 list and one is empty:
List<string> foo = new List<string>(){ "Ali","wall-e","Ellie" };
List<string> bar = new List<string>();
And I obtain the Cartesian Product of 2:
var q = from f in foo
from b in bar
select new {f,b};
As bar is empty LINQ returns an empty result set.
Question: How can I write the above query so that I can receive this result set:
Ali,NULL
Wall-e,NULL
Ellie,NULL
Maybe this is what you want:
var q = from f in foo.DefaultIfEmpty()
from b in bar.DefaultIfEmpty()
select new {f,b};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With