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. Show null results through the LEFT JOIN with Linq

Show null results through the LEFT JOIN with Linq

Scheduled Pinned Locked Moved LINQ
databasecsharplinqquestion
2 Posts 2 Posters 8 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.
  • U Offline
    U Offline
    User 10850492
    wrote on last edited by
    #1

    I have a SQL query:

    SELECT A.Codplano, A.Secao, A.Setor,A.Subsetor,A.Contato, ISNULL(B.Subord,'NÃO
    LANÇADA')AS Situacao
    FROM vwPLANODIN A LEFT JOIN LANCADA B
    ON A.Codplano = B.Subord
    and B.Data = '2014-06-10'
    WHERE B.ID IS NULL and A.Sitio = 7341

    Written in Linq:

    var cob = from A in dataClass.vwPLANODINs
    join B in dataClass.LANCADAs on new { A.Codplano, Data = data }
    equals new { Codplano = B.Subord, Data = Convert.ToString(B.Data) } into B_join
    from B in B_join.DefaultIfEmpty()
    where
    B.Data == null &&
    A.Sitio == local
    select new
    {
    A.Codplano,
    A.Secao,
    A.Setor,
    A.Subsetor,
    A.Contato,
    Situacao = (B.Subord ?? "N/A")
    };

    I have to show in a Gridview data not recorded, the SQL query returns what I need, but the Linq query, returns the exact opposite.:confused:

    M 1 Reply Last reply
    0
    • U User 10850492

      I have a SQL query:

      SELECT A.Codplano, A.Secao, A.Setor,A.Subsetor,A.Contato, ISNULL(B.Subord,'NÃO
      LANÇADA')AS Situacao
      FROM vwPLANODIN A LEFT JOIN LANCADA B
      ON A.Codplano = B.Subord
      and B.Data = '2014-06-10'
      WHERE B.ID IS NULL and A.Sitio = 7341

      Written in Linq:

      var cob = from A in dataClass.vwPLANODINs
      join B in dataClass.LANCADAs on new { A.Codplano, Data = data }
      equals new { Codplano = B.Subord, Data = Convert.ToString(B.Data) } into B_join
      from B in B_join.DefaultIfEmpty()
      where
      B.Data == null &&
      A.Sitio == local
      select new
      {
      A.Codplano,
      A.Secao,
      A.Setor,
      A.Subsetor,
      A.Contato,
      Situacao = (B.Subord ?? "N/A")
      };

      I have to show in a Gridview data not recorded, the SQL query returns what I need, but the Linq query, returns the exact opposite.:confused:

      M Offline
      M Offline
      mylogics
      wrote on last edited by
      #2

      from A in dataClass.vwPLANODINs
      join B in dataClass.LANCADAs on new { A.Codplano, Data = data }
      equals new { Codplano = B.Subord, Data = Convert.ToString(B.Data) } into B_join
      from B in B_join.DefaultIfEmpty(new LANCADAs{Data == null})
      select new
      {
      A.Codplano,
      A.Secao,
      A.Setor,
      A.Subsetor,
      A.Contato,
      Situacao = (B.Subord ?? "N/A")
      };

      something like this will work.

      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