LINQ dynamic where clause against generic list of custom objects

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi, I was wondering if there is a way to build a dynamic where clause, seems to be popular issue, but I cant find exactly what I am looking for.<font face=Arial size=2></font>
<span class=Apple-style-span style="white-space:normal

<span class=Apple-style-span style="white-space:normal For example, I have a Person class, with FirstName, and LastName properties.
<span class=Apple-style-span style="white-space:normal

<span class=Apple-style-span style="white-space:normal I have a collection of Person objects, at run time I am passed a list of first names, I want to now filter this collection to only include the list of first names, but I do not know how many first names I will filter on, etc...
<span class=Apple-style-span style="white-space:normal

<span class=Apple-style-span style="white-space:normal
<span class=Apple-style-span style="white-space:normal var query = from person in personList 
<blockquote class=webkit-indent-blockquote style="border-right:medium none;padding-right:0px;border-top:medium none;padding-left:0px;padding-bottom:0px;margin:0px 0px 0px 40px;border-left:medium none;padding-top:0px;border-bottom:medium none        where person.FirstName == ??</blockquote>
<span class=Apple-style-span style="white-space:normal
I seen things about the predicate builder class, is there another alternative? or if I use that, what do I need to add to the person class to make it work? Do I need to make it IEnumerable or anything like that?
<span class=Apple-style-span style="white-space:normal

<span class=Apple-style-span style="white-space:normal THanks

<span class=Apple-style-span style="white-space:normal

<span class=Apple-style-span style="white-space:normal


View the full article
 
Back
Top