Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

using linq to sql where predicates

Hi,

If I have the following code:
dim costumeg as new costumegroup

'some code to populate costumeg here

'then we want to get costumegroups that are not the costumeG.
Dim query = GeneralHelper.CostumeGroups.Where(Function(x) .....

I've not used predicates before and am just feeling my way into linq to sql...

What do I need to do in this predicate?

The code plus a quick description would be good.

Thanks in advance.
Avatar of brutaldev
brutaldev
Flag of South Africa image

A predicate is just a single parameter anonymous method that takes in an object and returns a boolean.

The shorthand here is that you want a function that takes in a costumegroup object and returns a boolean check that the passes in object does not equal the one created earlier. You can obviously use normal IF starement constraints like && and properties of the objects as well.
GeneralHelper.CostumeGroups.Where(Function(cg) cg <> costumeg)

Open in new window

Avatar of scm0sml
scm0sml

ASKER

excuse the stupidity but i'm doing:
Dim query = GeneralHelper.CostumeGroups.Where(Function(cg) cg <> costumeg)

and getting:
Error      3      Overload resolution failed because no accessible 'Where' can be called with these arguments:
    Extension method 'Public Function Where(predicate As System.Func(Of CostumeGroup, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of CostumeGroup)' defined in 'System.Linq.Enumerable': Nested function does not have a signature that is compatible with delegate 'System.Func(Of CostumeGroup, Integer, Boolean)'.
 
ASKER CERTIFIED SOLUTION
Avatar of scm0sml
scm0sml

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
Avatar of scm0sml

ASKER

This was the code i needed to solve my query
Sorry I couldn't assist here, I was in a C# mindset when I replied to this and didn't get the VB.NET syntax right (keywords instead of operators).