<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Linq Query question</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2009 : Linq Query question</description>
  <pubDate>Wed, 29 Apr 2026 00:42:58 -700</pubDate>
  <lastBuildDate>Wed, 23 Dec 2009 10:43:11 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=1462</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Linq Query question : IdeaBlade.Linq  </title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5980#5980</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=4" rel="nofollow">GregD</a><br /><strong>Subject:</strong> 1462<br /><strong>Posted:</strong> 23-Dec-2009 at 10:43am<br /><br />IdeaBlade.Linq]]>
   </description>
   <pubDate>Wed, 23 Dec 2009 10:43:11 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5980#5980</guid>
  </item> 
  <item>
   <title>Linq Query question : Hey, GregD, can you please tell...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5419#5419</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=454" rel="nofollow">monkeyking</a><br /><strong>Subject:</strong> 1462<br /><strong>Posted:</strong> 17-Sep-2009 at 8:42pm<br /><br />Hey, GregD, can you please tell me what i should import to get the PredicateBuilder class?&nbsp;]]>
   </description>
   <pubDate>Thu, 17 Sep 2009 20:42:07 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5419#5419</guid>
  </item> 
  <item>
   <title>Linq Query question : thanks GregD, that&amp;#039;s helpful ...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5413#5413</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=454" rel="nofollow">monkeyking</a><br /><strong>Subject:</strong> 1462<br /><strong>Posted:</strong> 17-Sep-2009 at 6:17pm<br /><br />thanks GregD, that's helpful]]>
   </description>
   <pubDate>Thu, 17 Sep 2009 18:17:25 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5413#5413</guid>
  </item> 
  <item>
   <title>Linq Query question : Here&amp;#039;s a second variation...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5361#5361</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=4" rel="nofollow">GregD</a><br /><strong>Subject:</strong> 1462<br /><strong>Posted:</strong> 10-Sep-2009 at 3:07pm<br /><br />Here's a second variation of the PredicateBuilder approach:<br><br>&nbsp;&nbsp;&nbsp; private void DoItUsingPredicateBuilder() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(".....Use the PredicateBuilder...");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;string&gt; lastNames = new string&#091;&#093; {"Davolio", "Fuller", "Buchanan"}.ToList();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var expr = PredicateBuilder.False&lt;Employee&gt;();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (string lastName in lastNames) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Make a new variable for this iteration's lastName value; otherwise,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // because of delayed execution, all expressions constructed below<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // will use the last-encountered version of lastName.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string lastNameThisIteration = lastName;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; expr = expr.Or(e =&gt; e.LastName == lastNameThisIteration);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;Employee&gt; employees = _mgr.Employees.Where(expr).ToList();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //foreach (Employee anEmployee in employees) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; Console.WriteLine(anEmployee.LastName);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //PromptToContinue();<br>&nbsp;&nbsp;&nbsp; }<br><br>]]>
   </description>
   <pubDate>Thu, 10 Sep 2009 15:07:36 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5361#5361</guid>
  </item> 
  <item>
   <title>Linq Query question : You can do this with the DevForce...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5359#5359</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=4" rel="nofollow">GregD</a><br /><strong>Subject:</strong> 1462<br /><strong>Posted:</strong> 10-Sep-2009 at 2:07pm<br /><br />You can do this with the DevForce PredicateBuilder. I'll show you that in a second, but just to cover the other alternatives:<br><br>1. You can bring the complete list of entities to the client and filter it there:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;string&gt; lastNames = new List&lt;string&gt;();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastNames.Add("Davolio");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastNames.Add("Fuller");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastNames.Add("Buchanan");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var employees = _mgr.Employees.ToList().Where(e =&gt; lastNames.Contains(e.LastName));<br><br>2.&nbsp;&nbsp; You can use a Remote Service Method call to do the above on the server, then ship down only the results;<br><br>3.&nbsp;&nbsp; You can hand-code the query with lots of ORs in the Where clause<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;Employee&gt; employees = _mgr.Employees.Where(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e =&gt; e.LastName == "Davolio" ||<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.LastName == "Fuller" || <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.LastName == "Buchanan").ToList();<br><br>Choices 1 and 3, of course, are either impossible or unacceptable in many scenarios; and choice 2 is maybe more trouble than you'd like to go to. So here's how you do it with the PredicateBuilder, which basically automates the process of&nbsp; constructing a query like #3:<br><br>&nbsp;&nbsp;&nbsp; private void DoItUsingPredicateBuilder() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;string&gt; lastNames = new List&lt;string&gt;();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastNames.Add("Davolio");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastNames.Add("Fuller");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastNames.Add("Buchanan");<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var tests = EmployeeLastNameTests(lastNames).ToArray();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (0 == tests.Length) return;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var employeeLastNamePredicate = PredicateBuilder.Or(tests);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;Employee&gt; employees = _mgr.Employees.Where(employeeLastNamePredicate).ToList();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //foreach (Employee anEmployee in employees) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; Console.WriteLine(anEmployee.LastName);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //PromptToContinue();<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; private IEnumerable&lt;Expression&lt;Func&lt;Employee, bool&gt;&gt;&gt; EmployeeLastNameTests(IEnumerable&lt;String&gt; words) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (var each in words) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var word = each;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; yield return e =&gt; e.LastName.Contains(word);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>]]>
   </description>
   <pubDate>Thu, 10 Sep 2009 14:07:44 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5359#5359</guid>
  </item> 
  <item>
   <title>Linq Query question : i have a list of stock names,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5349#5349</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=454" rel="nofollow">monkeyking</a><br /><strong>Subject:</strong> 1462<br /><strong>Posted:</strong> 09-Sep-2009 at 11:00pm<br /><br />i have a list of stock names, let's call it 'stockNames' (List&lt;string&gt; stockNames) and i have a 'Stock' table, which are a set of stock entities. now I want to use Linq to query the entities which their names are listed in 'stockName' list. <br><br>I used query as that, 'var query = entityManager.Stocks.where(o=&gt;(stockNames.Contains(o.name)));'. but List&lt;string&gt;.Contains(string) can't be used in the Linq 'where' clause. is there any other way to resolve this?<br><br>Regards<br>John<br>]]>
   </description>
   <pubDate>Wed, 09 Sep 2009 23:00:05 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1462&amp;PID=5349#5349</guid>
  </item> 
 </channel>
</rss>