linq cross join. if collection is empty still produce rows with that specific column null.
-
need help with this query. // goal make cnt == 5; and row.YearID is null for every item var crossjoin_forumquestion = from businessid in new List<Int32>() { 1, 2, 3, 4, 5 } from yearid in new List<Int32>() { } select new { BusinessID = businessid, YearID = yearid }; Int32 cnt = 0; foreach (var row in crossjoin_forumquestion) { cnt++; } thanks, -lm
-
need help with this query. // goal make cnt == 5; and row.YearID is null for every item var crossjoin_forumquestion = from businessid in new List<Int32>() { 1, 2, 3, 4, 5 } from yearid in new List<Int32>() { } select new { BusinessID = businessid, YearID = yearid }; Int32 cnt = 0; foreach (var row in crossjoin_forumquestion) { cnt++; } thanks, -lm
Try this:
var crossjoin_forumquestion = from businessid in new List<Int32>() { 1, 2, 3, 4, 5 }
from yearid in new List<Int32>() { }.DefaultIfEmpty()
select new
{
BusinessID = businessid,
YearID = yearid
};Int32 cnt = 0;
foreach (var row in crossjoin_forumquestion)
{
cnt++;
}How spooky - the second time in two days I've told somebody about
DefaultIfEmpty()
.Deja View - the feeling that you've seen this post before.
-
Try this:
var crossjoin_forumquestion = from businessid in new List<Int32>() { 1, 2, 3, 4, 5 }
from yearid in new List<Int32>() { }.DefaultIfEmpty()
select new
{
BusinessID = businessid,
YearID = yearid
};Int32 cnt = 0;
foreach (var row in crossjoin_forumquestion)
{
cnt++;
}How spooky - the second time in two days I've told somebody about
DefaultIfEmpty()
.Deja View - the feeling that you've seen this post before.
that works .. thanks! i need to start reading a linq book.. looks very powerful for sure.