Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

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.
0
scm0sml
Asked:
scm0sml
  • 3
  • 2
1 Solution
 
brutaldevCommented:
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

0
 
scm0smlAuthor Commented:
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)'.
 
0
 
scm0smlAuthor Commented:
got it working with this in the end:
Dim query = GeneralHelper.CostumeGroups.Where(Function(cg As CostumeGroup) Not cg.Equals(costumeg))
0
 
scm0smlAuthor Commented:
This was the code i needed to solve my query
0
 
brutaldevCommented:
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).
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now