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