using linq to sql where predicates

Posted on 2011-10-25
Last Modified: 2012-06-21

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.
Question by:scm0sml
    LVL 11

    Expert Comment

    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


    Author Comment

    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)'.

    Accepted Solution

    got it working with this in the end:
    Dim query = GeneralHelper.CostumeGroups.Where(Function(cg As CostumeGroup) Not cg.Equals(costumeg))

    Author Closing Comment

    This was the code i needed to solve my query
    LVL 11

    Expert Comment

    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).

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now