Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. linq cross join. if collection is empty still produce rows with that specific column null.

linq cross join. if collection is empty still produce rows with that specific column null.

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqhelp
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leblanc Meneses 0
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • L Leblanc Meneses 0

      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

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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.

      My blog | My articles | MoXAML PowerToys

      L 1 Reply Last reply
      0
      • P Pete OHanlon

        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.

        My blog | My articles | MoXAML PowerToys

        L Offline
        L Offline
        Leblanc Meneses 0
        wrote on last edited by
        #3

        that works .. thanks! i need to start reading a linq book.. looks very powerful for sure.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups