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. I am stuck wit Linq to Sql "NOT IN" - (Solved)

I am stuck wit Linq to Sql "NOT IN" - (Solved)

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqhelptutorial
1 Posts 1 Posters 3 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.
  • A Offline
    A Offline
    Andy_L_J
    wrote on last edited by
    #1

    In sql i would do this:

    SELECT t.Id
    FROM table1 t
    WHERE t.Id NOT IN(
    SELECT t.Id
    FROM table1 t
    right join table2 t2
    on t.Id = t2.table1_Id
    )

    which returns all the records in table1 that are not in table2. I am stumped as to how to convert this to Linq to SQL. Any pointers? [Answer Found] I need to use the Except method:

    var res1 = from t in table1 select t.Id;
    var res2 = from t2 in table2 select t2.table1_Id;
    var res3 = t.Except(t2);

    :doh:

    I don't speak Idiot - please talk slowly and clearly "I have sexdaily. I mean dyslexia. Fcuk!" Driven to the arms of Heineken by the wife

    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