Click here to Skip to main content
13,598,615 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 27 Feb 2012
Licenced CPOL

Filtering records from List similar to Sql IN Operator using LINQ

, 27 Feb 2012
Rate this:
Please Sign up or sign in to vote.
Filtering records from List similar to Sql IN Operator using LINQ
WHERE is Extension method of IEnumerable<t> which takes a predicate.
Predicate is a delegate which points to the Method which takes TSource(Type of Source) and return boolean based on some condition applied on each element of the Source.This is basically similar to "WHERE ID='abc'" in SQL.

So how to filter if we want to filter Source element against multiple condition like WHERE ID IN ('abc,'def').
I had a requirement where i wanted to filter all the files with extension matching with the extensions defined in App.config file(delimited with comma), but we don't have any extension method on IEnumerable to do this WHERE IN kind of filter. To do this i did it like following.

List<string> allReleaseAttachments = GetAllAttachments()//
List<string> attachments = allReleaseAttachments.Where(s=>{
                bool contain=false;
                foreach(string extension in allExtensions)
                return contain;
                return contain;

If you have requirement of Filtering similar to "WHERE IN" Condition you can create Extension method on IEnumerable<t> with name say WHEREIN can pass the list on which you want to check and can return boolean.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Technical Lead Microlise
India India
No Biography provided

You may also be interested in...


Comments and Discussions

Generalthanks nikhi Pin
Rishikesh_Singh27-Feb-12 18:37
memberRishikesh_Singh27-Feb-12 18:37 
GeneralReason for my vote of 5 nice one Pin
nikhi _singh27-Feb-12 18:23
membernikhi _singh27-Feb-12 18:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.180621.3 | Last Updated 27 Feb 2012
Article Copyright 2012 by Rishikesh_Singh
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid