swgdesign
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;
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"
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)
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)
Within the function where you defined this query, you have also declared another variable named "o".
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
ASKER
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.
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)
ASKER
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)
Causes the same issue as you are using ot in 3 places including the sub query!
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rewrote the query to use .Contains