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. Outer join on multiple keys

Outer join on multiple keys

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqhelptutorial
2 Posts 2 Posters 0 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.
  • S Offline
    S Offline
    sameerhanda
    wrote on last edited by
    #1

    Ok, I tried converting the following query into a LINQ outerjoin query select b.sProgID,a.sProgName1, a.nProgCode, b.bCurrentPrgrm from ABA.dbo.ResidentProgram as b left join ABA.dbo.Program A on A.sProgID=B.sProgID and A.nProgCode=B.nProgCode where b.nSSN = ? and bCurrentPrgrm = -1 and a.sProgID = b.sProgID I got upto the following before I had to post in here.. var q = from c in _DbAba.ResidentPrograms join o in _DbAba.Programs on c.sProgID equals o.sProgID into ps from p in ps.DefaultIfEmpty() select new { What I cannot figure out is how to translate the "A.sProgID=B.sProgID and A.nProgCode=B.nProgCode" into LINQ....Any help or advice would be greatly appreciated.

    H 1 Reply Last reply
    0
    • S sameerhanda

      Ok, I tried converting the following query into a LINQ outerjoin query select b.sProgID,a.sProgName1, a.nProgCode, b.bCurrentPrgrm from ABA.dbo.ResidentProgram as b left join ABA.dbo.Program A on A.sProgID=B.sProgID and A.nProgCode=B.nProgCode where b.nSSN = ? and bCurrentPrgrm = -1 and a.sProgID = b.sProgID I got upto the following before I had to post in here.. var q = from c in _DbAba.ResidentPrograms join o in _DbAba.Programs on c.sProgID equals o.sProgID into ps from p in ps.DefaultIfEmpty() select new { What I cannot figure out is how to translate the "A.sProgID=B.sProgID and A.nProgCode=B.nProgCode" into LINQ....Any help or advice would be greatly appreciated.

      H Offline
      H Offline
      Howard Richards
      wrote on last edited by
      #2

      Check out this link[^] - it's VB but the same principle applies. Use an AND in the join, e.g.

      var q = from b in _DbAba.ResidentPrograms
      join a in _DbAba.Programs on b.sProgID equals a.sProgID
      && a.nProgCode = b.nProgCode
      into ps ....

      'Howard

      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