<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Dynamic Searching using LINQ - Dataset + Joins</title><link>http://blogs.msdn.com/vbteam/archive/2009/07/10/dynamic-searching-using-linq-dataset-joins.aspx</link><description>About two years ago I posted some code that shows how to dynamically construct LINQ queries at runtime . On average there's a couple questions per month about trying it in some edge case, and usually the support already exists within the API. Recently</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Dynamic Searching using LINQ - Dataset + Joins</title><link>http://blogs.msdn.com/vbteam/archive/2009/07/10/dynamic-searching-using-linq-dataset-joins.aspx#9850073</link><pubDate>Mon, 27 Jul 2009 18:29:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9850073</guid><dc:creator>Dreamn</dc:creator><description>&lt;p&gt;why so much of hassle just write the basic query and append where depending on condition&lt;/p&gt;
&lt;p&gt;IEnumerable&amp;lt;Foo&amp;gt; query =null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;if (!string.IsNullOrEmpty(_paramsCol[4]))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt;		query = li.Where(x =&amp;gt; x.SomeField == _paramsCol[4]);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp;if (!string.IsNullOrEmpty(_paramsCol[5]))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt;		query = li.Where(x =&amp;gt; x.SomeField == _paramsCol[5]);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
</description></item><item><title>re: Dynamic Searching using LINQ - Dataset + Joins</title><link>http://blogs.msdn.com/vbteam/archive/2009/07/10/dynamic-searching-using-linq-dataset-joins.aspx#9850244</link><pubDate>Mon, 27 Jul 2009 22:03:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9850244</guid><dc:creator>Jonathan Aneja</dc:creator><description>&lt;p&gt;Well when you say &amp;quot;x =&amp;gt; x.SomeField&amp;quot; - the property &amp;quot;SomeField&amp;quot; has to be known *statically* - you can't change that at runtime.&lt;/p&gt;
&lt;p&gt;By using the DynamicCondition API, you can have the name of the field picked *dynamically* at runtime using only one line of code (db.Orders.CreateCondition(...)). &amp;nbsp;&lt;/p&gt;
&lt;p&gt;For example if a user has a search form where they could search by any field, you'd have to write a *lot* of if/else stuff to cover every possible case, and every time you add a field to your table you'd need to update this logic.&lt;/p&gt;
&lt;p&gt;For more information on the scenario please see the previous blog entry on this topic: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx"&gt;http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope that helps!&lt;/p&gt;
&lt;p&gt;Jonathan Aneja&lt;/p&gt;
&lt;p&gt;Program Manager, VB Team&lt;/p&gt;
</description></item><item><title>re: Dynamic Searching using LINQ - Dataset + Joins</title><link>http://blogs.msdn.com/vbteam/archive/2009/07/10/dynamic-searching-using-linq-dataset-joins.aspx#9858774</link><pubDate>Thu, 06 Aug 2009 09:17:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9858774</guid><dc:creator>Jaideep</dc:creator><description>&lt;p&gt;avery good article.... just wanted to know, if we can get a c# version of this. i tried converting it to c# but it is giving compile errors&lt;/p&gt;
</description></item><item><title>re: Dynamic Searching using LINQ - Dataset + Joins</title><link>http://blogs.msdn.com/vbteam/archive/2009/07/10/dynamic-searching-using-linq-dataset-joins.aspx#9859715</link><pubDate>Fri, 07 Aug 2009 03:14:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9859715</guid><dc:creator>Jonathan Aneja</dc:creator><description>&lt;p&gt;Hey Jaideep,&lt;/p&gt;
&lt;p&gt;Can you post the compile errors that you're seeing? &amp;nbsp;When people have translated this in the past the only error I've seen is that some of the calls to GetType() are partially qualified whereas C#'s typeof() requires full namespace qualification. &amp;nbsp;That might be the issue.&lt;/p&gt;
&lt;p&gt;Hope that helps!&lt;/p&gt;
&lt;p&gt;Jonathan&lt;/p&gt;
</description></item><item><title>re: Dynamic Searching using LINQ - Dataset + Joins</title><link>http://blogs.msdn.com/vbteam/archive/2009/07/10/dynamic-searching-using-linq-dataset-joins.aspx#9910858</link><pubDate>Wed, 21 Oct 2009 19:44:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9910858</guid><dc:creator>Michal Rovnanik</dc:creator><description>&lt;p&gt;Hi Jonathan,&lt;/p&gt;
&lt;p&gt;thanks for all the code, I appreciate it. I face a problem with dynamic query construction in my application. I load data into datatables in runtime (from xml, csv, sql server and nsf) along with joins definition among the tables.&lt;/p&gt;
&lt;p&gt;Sample code (just a trial one):&lt;/p&gt;
&lt;p&gt;Dim personnel As DataTable = Me.iDataset.Tables(0)&lt;/p&gt;
&lt;p&gt;Dim workrecords As DataTable = Me.iDataset.Tables(1)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim query = _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;From per In personnel _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;From wr In workrecords&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim condition1 = query.CreateMultiColumnCondition( _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;quot;per.OSCIS&amp;quot;, Compare.Equal, &amp;quot;wr.OSCIS&amp;quot;)&lt;/p&gt;
&lt;p&gt;Calling CreateMultiColumnCondition causes an exception like this:&lt;/p&gt;
&lt;p&gt; &amp;quot;Public member 'CreateMultiColumnCondition' on type '&amp;lt;SelectManyIterator&amp;gt;d__31(Of DataRow,DataRow,VB$AnonymousType_0(Of DataRow,DataRow))' not found.&amp;quot; &lt;/p&gt;
&lt;p&gt;It implies some kind of type casting error. Where am I going in wrong? The dataset is not strongly-typed one.&lt;/p&gt;
&lt;p&gt;Thanks very much, any help is appreciated&lt;/p&gt;
&lt;p&gt;Michal&lt;/p&gt;
</description></item></channel></rss>