<?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>Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx</link><description>A common requirement in forms-over-data applications is that users be able to search by any combination of fields to construct a dynamic query at run time. For example, the search feature in this application allows the user to find all records that meet</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#4636888</link><pubDate>Thu, 30 Aug 2007 03:30:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4636888</guid><dc:creator>tomasp</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;there is a way for building queries dynamically without the need to build any expression trees manually and withot loosing the type safety (even though your sample is 'safer' than the DynamicQueries sample, there are still a few possible problems). I wrote about it here: &lt;a rel="nofollow" target="_new" href="http://tomasp.net/blog/dynamic-linq-queries.aspx"&gt;http://tomasp.net/blog/dynamic-linq-queries.aspx&lt;/a&gt;. It is written in C#, but I guess that C# and VB have similar expressive power, so I would expect that same thing could be done in VB as well (but correct me if I'm wrong!).&lt;/p&gt;
</description></item><item><title>Visual Basic Content Rollup for July and August</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#4791824</link><pubDate>Thu, 06 Sep 2007 22:47:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4791824</guid><dc:creator>Beth Massi - Sharing the goodness that is VB</dc:creator><description>&lt;p&gt;So I decided to post a summary of all the content the VB team members, including myself, have created&lt;/p&gt;
</description></item><item><title>Lambda Expressions and Expression Trees</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#4874108</link><pubDate>Wed, 12 Sep 2007 05:10:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4874108</guid><dc:creator>The Visual Basic Team</dc:creator><description>&lt;p&gt;Hi there! My name is Tim, and I'm the dev lead for the VB compiler team. Recently Amanda convinced me&lt;/p&gt;
</description></item><item><title>Izindaba #9</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#4905933</link><pubDate>Fri, 14 Sep 2007 09:20:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4905933</guid><dc:creator>From the software development trenches</dc:creator><description>&lt;p&gt;Time for another weekly roundup of news that focuses on .NET, agile and general development related content&lt;/p&gt;
</description></item><item><title>VB 2008 Language Deep Dive - Presentation Materials (Jonathan Aneja)</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#8883487</link><pubDate>Thu, 21 Aug 2008 08:20:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8883487</guid><dc:creator>The Visual Basic Team</dc:creator><description>&lt;p&gt;Last week I got the chance to visit the Toronto .NET User Group and give a talk on all the great new&lt;/p&gt;
</description></item><item><title>[翻译]使用LINQ实现动态搜索(Implementing Dynamic Searching Using LINQ)</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#8903954</link><pubDate>Thu, 28 Aug 2008 22:10:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8903954</guid><dc:creator>G yc {Son of VB.NET}</dc:creator><description>&lt;p&gt;原文链接：&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/vbteam"&gt;http://blogs.msdn.com/vbteam&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9471862</link><pubDate>Thu, 12 Mar 2009 19:13:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9471862</guid><dc:creator>Bruno Santos</dc:creator><description>&lt;p&gt;Hi. Thanks Great. But It doesn't seem to work for the Like operator between Strings.&lt;/p&gt;
&lt;p&gt;Can you fix that?&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9472193</link><pubDate>Thu, 12 Mar 2009 23:59:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9472193</guid><dc:creator>Jonathan Aneja</dc:creator><description>&lt;p&gt;Hey Bruno,&lt;/p&gt;
&lt;p&gt;I can't seem to repro a problem with the Like operator - either in the ConditionBuilder control or in the API itself.&lt;/p&gt;
&lt;p&gt;Dim c = db.Orders.CreateCondition(&amp;quot;CustomerID&amp;quot;, Compare.Like, &amp;quot;A*&amp;quot;)&lt;/p&gt;
&lt;p&gt;Dim filteredQuery = db.Orders.Where(c)&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;Likewise in the control if I choose the Like operator from the dropdown and pass a valid string I get normal VB-Like-Operator semantics.&lt;/p&gt;
&lt;p&gt;Could you post more info on the case that's not working for you?&lt;/p&gt;
&lt;p&gt;Thanks,&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: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9472954</link><pubDate>Fri, 13 Mar 2009 13:19:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9472954</guid><dc:creator>Bruno Santos</dc:creator><description>&lt;p&gt;Hi Jonathan. First, Thank you for such a fast reply.&lt;/p&gt;
&lt;p&gt;What I have is a web form where the user can fill it up and select in a cbox if he wants the condition for that field to be AND or OR.&lt;/p&gt;
&lt;p&gt;For example the FirstName field. If I select OR, the query whould be:&lt;/p&gt;
&lt;p&gt;Dim condition1 = db.Members.CreateCondition(&amp;quot;FName&amp;quot;, Compare.Like, fName)&lt;/p&gt;
&lt;p&gt;Dim fdx = condition1 And condition2 _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'And condition3 And condition4 And _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'condition5 And condition6 And condition7 And condition8 And _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'condition9 And condition10&lt;/p&gt;
&lt;p&gt;Dim filteredQuery = db.Members.Where(fdx)&lt;/p&gt;
&lt;p&gt;Dim query = From row In filteredQuery _&lt;/p&gt;
&lt;p&gt;Order By row.MemberGUID, row.BaseMemberID _&lt;/p&gt;
&lt;p&gt;Select row&lt;/p&gt;
&lt;p&gt;When the Query is executed it returns:&lt;/p&gt;
&lt;p&gt;&amp;quot;LINQ to Entities does not recognize the method 'Boolean LikeString(System.String, System.String, Microsoft.VisualBasic.CompareMethod)' method, and this method cannot be translated into a store expression.&amp;quot;&lt;/p&gt;
&lt;p&gt;I've read that Linq doesn't have the Like operator yet. So What you think that I can do? Am I doing this the right way?&lt;/p&gt;
&lt;p&gt;I'm now thinking in building the where clause as a String... and executed via Linq to Entities...&lt;/p&gt;
&lt;p&gt;But I prefered to use you way.&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9473653</link><pubDate>Sat, 14 Mar 2009 00:04:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9473653</guid><dc:creator>Jonathan Aneja</dc:creator><description>&lt;p&gt;ah, ok, there's two seperate issues here. &amp;nbsp;LINQ and the DynamicCondition API both do support the Like operator, but in this case the particular LINQ *provider* doesn't support translating Like.&lt;/p&gt;
&lt;p&gt;LINQ to SQL and LINQ to Objects support Like, but LINQ to Entities doesn't. &amp;nbsp;I'll follow up with the Entities team and see if it's something they can add support for. &amp;nbsp;You can try using Substring or some of the BCL string functions as I'm pretty sure they'll support those.&lt;/p&gt;
&lt;p&gt;HTH,&lt;/p&gt;
&lt;p&gt;Jonathan&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9481129</link><pubDate>Mon, 16 Mar 2009 13:17:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9481129</guid><dc:creator>Bruno Santos</dc:creator><description>&lt;p&gt;Hi Jonathan. Just Another small question.&lt;/p&gt;
&lt;p&gt;I have a Sql user function that calcs a persons age and I wanted to use that in a query.&lt;/p&gt;
&lt;p&gt;I've heard that Model defined functions are not in the shipping Entity Framework (only in .NET 4.0)&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://stackoverflow.com/questions/609959/entity-framework-model-defined-functions"&gt;http://stackoverflow.com/questions/609959/entity-framework-model-defined-functions&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But I still whated to something like this:&lt;/p&gt;
&lt;p&gt;SELECT * FROM Members as m&lt;/p&gt;
&lt;p&gt;Where 	m.FName like @FName or &lt;/p&gt;
&lt;p&gt;m.LName like @LName or	&lt;/p&gt;
&lt;p&gt;ufn_GetAge ( m.DOB, GETDATE() ) &amp;gt;= @AgeMin or&lt;/p&gt;
&lt;p&gt;ufn_GetAge ( m.DOB, GETDATE() ) &amp;lt;= @AgeMax &lt;/p&gt;
&lt;p&gt;I know that I cant do that with Link to Entities. But I was trying to do it with Entity to SQL like this:&lt;/p&gt;
&lt;p&gt;Dim queryString As String = &amp;quot;SELECT VALUE m FROM Members as m&lt;/p&gt;
&lt;p&gt;Where 	m.FName = @FName and &lt;/p&gt;
&lt;p&gt;m.LName = @LName and&lt;/p&gt;
&lt;p&gt;ufn_GetAge] ( m.DOB, GETDATE() ) &amp;gt;= @AgeMin and&lt;/p&gt;
&lt;p&gt;[dbo].[ufn_GetAge] ( m.DOB, GETDATE() ) &amp;lt;= @AgeMax &lt;/p&gt;
&lt;p&gt;Dim membersQuery As New ObjectQuery(Of Members)(queryString, db, MergeOption.NoTracking)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;membersQuery.Parameters.Add(fNameParameter)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;membersQuery.Parameters.Add(lNameParameter)&lt;/p&gt;
&lt;p&gt;But That Doesnt seem to work. &lt;/p&gt;
&lt;p&gt;Can you point me out on the right direction?&lt;/p&gt;
&lt;p&gt;Thank you for your help.&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9484318</link><pubDate>Tue, 17 Mar 2009 21:17:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9484318</guid><dc:creator>Koen</dc:creator><description>&lt;p&gt;Hi I'm trying to use the library, but i fail when I combine 2 Like clauses together with and And. When I combine them with an OR it works, what is a bit weird for me.&lt;/p&gt;
&lt;p&gt;Can anybody help me with this?&lt;/p&gt;
&lt;p&gt;Thanks for any help!&lt;/p&gt;
&lt;p&gt;Here's my code:&lt;/p&gt;
&lt;p&gt;		If Not city.EndsWith(&amp;quot;*&amp;quot;) Then&lt;/p&gt;
&lt;p&gt;			city &amp;amp;= &amp;quot;*&amp;quot;&lt;/p&gt;
&lt;p&gt;		End If&lt;/p&gt;
&lt;p&gt;		If Not name.EndsWith(&amp;quot;*&amp;quot;) Then&lt;/p&gt;
&lt;p&gt;			name &amp;amp;= &amp;quot;*&amp;quot;&lt;/p&gt;
&lt;p&gt;		End If&lt;/p&gt;
&lt;p&gt;		Using db = New DataLayer.SIS2009Db.SIS2009DataContext()&lt;/p&gt;
&lt;p&gt;			Dim filter = Common.Condition.Create(db.Dealerships, &amp;quot;ds_City&amp;quot;, Common.Condition.Compare.Like, city)&lt;/p&gt;
&lt;p&gt;			Dim filter2 = Common.Condition.Create(db.Dealerships, &amp;quot;ds_Name&amp;quot;, Common.Condition.Compare.Like, name)&lt;/p&gt;
&lt;p&gt;			Dim endfilter = (filter And filter2)&lt;/p&gt;
&lt;p&gt;			Return db.Dealerships.Where(endfilter).ToList()&lt;/p&gt;
&lt;p&gt;		End Using&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9484375</link><pubDate>Tue, 17 Mar 2009 21:36:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9484375</guid><dc:creator>Jonathan Aneja</dc:creator><description>&lt;p&gt;Your code looks right, are you sure the data in the database matches both conditions?&lt;/p&gt;
&lt;p&gt;I just tried this on Northwind and it works fine:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim c = db.Orders.CreateCondition(&amp;quot;CustomerID&amp;quot;, Compare.Like, &amp;quot;A*&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim c2 = db.Orders.CreateCondition(&amp;quot;ShipAddress&amp;quot;, Compare.Like, &amp;quot;B*&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim filteredQuery = db.Orders.Where(c And c2)&lt;/p&gt;
&lt;p&gt;Try using DataContext.Log or SQL Profiler to see what SQL string is being sent to the database.&lt;/p&gt;
&lt;p&gt;HTH,&lt;/p&gt;
&lt;p&gt;Jonathan&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9503161</link><pubDate>Tue, 24 Mar 2009 05:09:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9503161</guid><dc:creator>Alex Mineev</dc:creator><description>&lt;p&gt;WRT ufn_GetAge: &amp;nbsp;eSQL&lt;/p&gt;
&lt;p&gt;GetDate() should be available under SqlServer namespace&lt;/p&gt;
&lt;p&gt;you can import GetAge into ssdl like this:&lt;/p&gt;
&lt;p&gt;&amp;lt;Function Name=&amp;quot;GetAge&amp;quot; StoreFunctionName=&amp;quot;ufn_GetAge &amp;quot; ReturnType=&amp;quot;Int&amp;quot;&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;Parameter Name=&amp;quot;dob&amp;quot; Type=&amp;quot;DateTime&amp;quot; Mode=&amp;quot;In&amp;quot; /&amp;gt; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;Parameter Name=&amp;quot;today&amp;quot; Type=&amp;quot;DateTime&amp;quot; Mode=&amp;quot;In&amp;quot; /&amp;gt; &lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;/Function&amp;gt;&lt;/p&gt;
&lt;p&gt;Once in ssdl, the function should be available in eSQL queries under the namespace defined in SSDL&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9801499</link><pubDate>Wed, 24 Jun 2009 16:48:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9801499</guid><dc:creator>masscomp</dc:creator><description>&lt;p&gt;I tried this following query:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim condition1 = ds.Code.CreateCondition(&amp;quot;OrgId&amp;quot;, Compare.Equal, 1)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim condition2 = ds.Code.CreateCondition(&amp;quot;CodeType&amp;quot;, Compare.Equal, &amp;quot;SECCOLOR&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim c = condition1 And condition2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim filteredQuery = ds.Code.Where(c)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim query = From row In filteredQuery _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Order By row _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Select row&lt;/p&gt;
&lt;p&gt;I get the following error in the CombineExpression function:&lt;/p&gt;
&lt;p&gt;The binary operator Equal is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'.&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9801703</link><pubDate>Wed, 24 Jun 2009 19:32:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9801703</guid><dc:creator>Jonathan Aneja</dc:creator><description>&lt;p&gt;The problem is the expression tree needs both sides of the expression to be the same type. &amp;nbsp;Try this instead:&lt;/p&gt;
&lt;p&gt;Dim value? = 1&lt;/p&gt;
&lt;p&gt;Dim condition1 = ds.Code.CreateCondition(&amp;quot;OrgId&amp;quot;, Compare.Equal, value)&lt;/p&gt;
&lt;p&gt;Now you're comparing a Nullable integer with another Nullable Integer and everything should work fine.&lt;/p&gt;
&lt;p&gt;HTH,&lt;/p&gt;
&lt;p&gt;Jonathan&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9802049</link><pubDate>Wed, 24 Jun 2009 23:31:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9802049</guid><dc:creator>masscomp</dc:creator><description>&lt;p&gt;Thanks, that worked for the integer and also works for boolean when using this dynamic query. &amp;nbsp;Those nullable variables didn't work when I tried to create the query in code. &amp;nbsp;ex.&lt;/p&gt;
&lt;p&gt;dim intOrgId? as integer = 1&lt;/p&gt;
&lt;p&gt;dim blnFalse? as boolean = false&lt;/p&gt;
&lt;p&gt;dim query= from row in ds.Code _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;where row.OrgId = intOrgId _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and row.CodeType = &amp;quot;SECCOLOR&amp;quot; _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and row.Inactive = blnFalse&lt;/p&gt;
&lt;p&gt;Dave&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9803807</link><pubDate>Thu, 25 Jun 2009 19:12:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9803807</guid><dc:creator>masscomp</dc:creator><description>&lt;p&gt;As stated above, 'like' doesn't work with linq - entities but after dynamically preparing the other conditions you can add conditions such as startswith, contains, endswith as follows:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim condition1 = ds.Cust.CreateCondition(&amp;quot;OrgId&amp;quot;, Compare.Equal, intOrgId)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim condition2 = ds.Cust.CreateCondition(&amp;quot;CustTypeId&amp;quot;, Compare.Equal, intCustType)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim c = condition1 And condition2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim filteredQuery = ds.Cust.Where(c)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim query = From row In filteredQuery _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Where row.SearchName.StartsWith(strSearchText) _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Order By row.SearchName&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Dim CustQuery = CType(query, DataServiceQuery(Of Cust))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;CustQuery.BeginExecute(AddressOf GetCustListByOrgCompleted, CustQuery)&lt;/p&gt;
&lt;p&gt;Dave&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9829011</link><pubDate>Fri, 10 Jul 2009 22:19:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829011</guid><dc:creator>usul</dc:creator><description>&lt;p&gt;I would like to be able to modify this.&lt;/p&gt;
&lt;p&gt;I have a dataset with two datatables&lt;/p&gt;
&lt;p&gt;(One Loaded From A CSV file)&lt;/p&gt;
&lt;p&gt;and &lt;/p&gt;
&lt;p&gt;(the other loaded from a query)&lt;/p&gt;
&lt;p&gt;what I would like to be able to do is&lt;/p&gt;
&lt;p&gt;set the criteria (i.e dtCSV.Field1=dtQuery.Field7 AND (dtCSV.Field5 != dtQuery.Field4 or dtCSV.Field5 != dtQuery.Field9)&lt;/p&gt;
&lt;p&gt;Returning dtQuery.Field1, dtCSV.Field5&lt;/p&gt;
&lt;p&gt;Basically I am updating a description field in a database based on CSVs from various vendors.&lt;/p&gt;
&lt;p&gt;I have everything worked out except the dynamic Linq (using the datasets and comparing the fields directly is too slow) I am hoping that I can get a smaller set containing just the records that need updates if any.&lt;/p&gt;
&lt;p&gt;I am new to Linq and not sure how to modify this to include the joins. &lt;/p&gt;
&lt;p&gt;thanks&lt;/p&gt;
&lt;p&gt;usul&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9829211</link><pubDate>Sat, 11 Jul 2009 04:14:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9829211</guid><dc:creator>VBTeam</dc:creator><description>&lt;p&gt;Hey Usul,&lt;/p&gt;
&lt;p&gt;It's definitely possible to do what you're looking for but it involves adding some functionality to the Condition API, so instead of trying to cram it in here I've written a separate blog entry that walks through how to do it:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/vbteam/archive/2009/07/10/dynamic-searching-using-linq-dataset-joins.aspx"&gt;http://blogs.msdn.com/vbteam/archive/2009/07/10/dynamic-searching-using-linq-dataset-joins.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope that helps!&lt;/p&gt;
&lt;p&gt;Jonathan&lt;/p&gt;
</description></item><item><title>re: Implementing Dynamic Searching Using LINQ</title><link>http://blogs.msdn.com/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx#9920839</link><pubDate>Wed, 11 Nov 2009 15:21:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9920839</guid><dc:creator>AlexB</dc:creator><description>&lt;p&gt;The code is missing 3 very important lines in case of you want to select rows &amp;quot;where&amp;quot; the field is &amp;quot;*&amp;quot; OR DBNULL.&lt;/p&gt;
&lt;p&gt;In the &amp;quot;Protected Shared Function CombineExpression&amp;quot; function i change the code to look like that:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; Protected Shared Function CombineExpression(ByVal left As Expression, _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ByVal condType As Compare, _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ByVal right As Expression) As Expression&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Join the Expressions based on the operator&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Select Case condType&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.Or : Return Expression.Or(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.And : Return Expression.And(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.Xor : Return Expression.ExclusiveOr(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.Equal : Return Expression.Equal(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.OrElse : Return Expression.OrElse(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.AndAlso : Return Expression.AndAlso(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.NotEqual : Return Expression.NotEqual(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.LessThan : Return Expression.LessThan(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.GreaterThan : Return Expression.GreaterThan(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.LessThanOrEqual : Return Expression.LessThanOrEqual(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.GreaterThanOrEqual : Return Expression.GreaterThanOrEqual(left, right)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Compare.Like&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'For the Like operator we encode a call to the LikeString method in the VB runtime&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim m = GetType(CompilerServices.Operators).GetMethod(&amp;quot;LikeString&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If right.Type Is System.DBNull.Value.GetType Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return Expression.Equal(left, Expression.Constant(Nothing))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return Expression.Call(m, left, right, Expression.Constant(CompareMethod.Binary))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case Else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Throw New ArgumentException(&amp;quot;Not a valid Condition Type&amp;quot;, &amp;quot;condType&amp;quot;, Nothing)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Select&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End Function&lt;/p&gt;
</description></item></channel></rss>