Link to home
Start Free TrialLog in
Avatar of swgdesign
swgdesignFlag for United Kingdom of Great Britain and Northern Ireland

asked on

linq NOT IN using datatables / AsEnumerable

I am not using a datacontext and so I am using datatables.AsEnumerable() to use LINQ as a subquery tool.

I have 2 datatables defined as follows;

 
Dim dtObjectTypes As DataTable = IMCSelect.getObjectTypes(-1, Application("logUsers"), 1).Tables(0)

Dim dtPermissions As DataTable = IMCSelect.getPermissions(iUserID, -1, Application("logUsers")).Tables(0)

Open in new window


I have started to write a LINQ query to get any items from dtObjectTypes that DO NOT appear in dtPermissions, but VS2010 is telling me the following error;

"o hides a variable in an enclosing block...etc"

 
Dim query = From o In dtObjectTypes.AsEnumerable() Where Not o.Field(Of Integer)("ID") = (From p In dtPermissions.AsEnumerable() Select p.Field(Of Integer)("TypeID") Select o)

Open in new window


Avatar of kaufmed
kaufmed
Flag of United States of America image

Within the function where you defined this query, you have also declared another variable named "o".
Avatar of swgdesign

ASKER

I get the error message, my questin was, what needs changing to get the query working?
Change "o" in your query to some other variable name.
as Kaufmed mentioned you double declared the same variable
How can I change 'o' when 'o' is an item of ObejctTypes that I need to return?

I've tried changing the last o and it errors.
Dim query = From MySuperAwesomeNewVariableThatWontHideAnythingBecauseItHasANewScope In dtObjectTypes.AsEnumerable() Where Not MySuperAwesomeNewVariableThatWontHideAnythingBecauseItHasANewScope.Field(Of Integer)("ID") = (From p In dtPermissions.AsEnumerable() Select p.Field(Of Integer)("TypeID") Select MySuperAwesomeNewVariableThatWontHideAnythingBecauseItHasANewScope)

Open in new window

Dim query = From ot In dtObjectTypes.AsEnumerable() Where Not ot.Field(Of Integer)("ID") = (From p In dtPermissions.AsEnumerable() Select p.Field(Of Integer)("TypeID") Select ot)

Open in new window


Causes the same issue as you are using ot in 3 places including the sub query!
Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of swgdesign
swgdesign
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Rewrote the query to use .Contains