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 "Not In" sql Query

Linq "Not In" sql Query

Scheduled Pinned Locked Moved LINQ
databasecsharplinqhelpquestion
4 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.
  • A Offline
    A Offline
    Amr M K
    wrote on last edited by
    #1

    Dear All, I just begun a rokect start in Linq its nice,but hard in begining,we get use in sql query for along,anyway I have problem in sql query convert it in Linq the query contain " where Colum not in (select Colum...)" I am using datatable to get the values Here the sql query SELECT * from Users where UserID not ( in Select UserID FROM AdditionalMailing WHERE CompanyID=2 ) i done slect from user table Dim linqUser = From vSelect In dtUsers1.AsEnumerable() select UserID=vSelect.Field(of long)("UserID") AND SELET Dim linqAddionalMailin = From vSelect In dtAdditionalMailingTable.AsEnumerable() _ Where vSelect.Field(Of String)("CompanyID") = CompanyID _ Select UserID = vSelect.Field(Of Long)("UserID") AND start comparing the result For Each User In linqUser For Each Mailing In linqAddionalMailin If User.UserID <> Mailing Then End If this ofcourse not the best way to done I dont want to loop in linqUser and start comparing thier is exact in linq ,but i dont want to use it ??? bcz maybe the two table dont have same structure note UserID in both table is LONG

    Yes. CreatiVity withOuT limiTs

    D 1 Reply Last reply
    0
    • A Amr M K

      Dear All, I just begun a rokect start in Linq its nice,but hard in begining,we get use in sql query for along,anyway I have problem in sql query convert it in Linq the query contain " where Colum not in (select Colum...)" I am using datatable to get the values Here the sql query SELECT * from Users where UserID not ( in Select UserID FROM AdditionalMailing WHERE CompanyID=2 ) i done slect from user table Dim linqUser = From vSelect In dtUsers1.AsEnumerable() select UserID=vSelect.Field(of long)("UserID") AND SELET Dim linqAddionalMailin = From vSelect In dtAdditionalMailingTable.AsEnumerable() _ Where vSelect.Field(Of String)("CompanyID") = CompanyID _ Select UserID = vSelect.Field(Of Long)("UserID") AND start comparing the result For Each User In linqUser For Each Mailing In linqAddionalMailin If User.UserID <> Mailing Then End If this ofcourse not the best way to done I dont want to loop in linqUser and start comparing thier is exact in linq ,but i dont want to use it ??? bcz maybe the two table dont have same structure note UserID in both table is LONG

      Yes. CreatiVity withOuT limiTs

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      This should work:

      from user in UserTable
      where !(from addMailing in AdditionalMailing
      select addMailing.UserID).Contains(user.UserID)
      select user;

      It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

      A 1 Reply Last reply
      0
      • D dan sh

        This should work:

        from user in UserTable
        where !(from addMailing in AdditionalMailing
        select addMailing.UserID).Contains(user.UserID)
        select user;

        It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

        A Offline
        A Offline
        Amr M K
        wrote on last edited by
        #3

        Thaaaaaaaaaaaaaaaaaanks man:thumbsup::thumbsup::thumbsup:

        Yes. CreatiVity withOuT limiTs

        D 1 Reply Last reply
        0
        • A Amr M K

          Thaaaaaaaaaaaaaaaaaanks man:thumbsup::thumbsup::thumbsup:

          Yes. CreatiVity withOuT limiTs

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          You should refer to this[^] link. Quite useful if you are learning LINQ infact anytime it is quite useful.

          It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

          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