<?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>Converting SQL to LINQ, Part 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx</link><description>This post assumes you’ve read my previous Converting SQL to LINQ posts. I haven’t had much in the way of specific requests for more LINQ posts, so I’d still welcome any suggestions that people want to offer. I did get one request about how to mimic the</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Airline Travel &amp;raquo; Converting SQL to LINQ, Part 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx#8468158</link><pubDate>Thu, 08 May 2008 04:06:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8468158</guid><dc:creator>Airline Travel &amp;raquo; Converting SQL to LINQ, Part 10: Like (Bill Horst)</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.travel-hilarity.com/airline_travel/?p=4392"&gt;http://www.travel-hilarity.com/airline_travel/?p=4392&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Converting SQL to LINQ, Part 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx#8468235</link><pubDate>Thu, 08 May 2008 04:30:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8468235</guid><dc:creator>Anthony</dc:creator><description>&lt;p&gt;Is the same for C# or is exclusive for VB?&lt;/p&gt;
</description></item><item><title>re: Converting SQL to LINQ, Part 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx#8472543</link><pubDate>Thu, 08 May 2008 18:57:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8472543</guid><dc:creator>Phil Weber</dc:creator><description>&lt;p&gt;Hi, Bill: Here are some LINQ-to-SQL (L2S) scenarios I'd like to see covered in more detail: &lt;/p&gt;
&lt;p&gt;- Using L2S with stored procedures when the developer or users do not have table-level access; &lt;/p&gt;
&lt;p&gt;- Refreshing the L2S Designer when the database schema changes; &lt;/p&gt;
&lt;p&gt;- Canceling pending changes to a record; &lt;/p&gt;
&lt;p&gt;- Using L2S in a disconnected scenario, such as a Web application where it is not practical to maintain state in a long-lived DataContext.&lt;/p&gt;
&lt;p&gt;Appreciate any insight you care to provide, thanks!&lt;/p&gt;
</description></item><item><title>re: Converting SQL to LINQ, Part 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx#8472572</link><pubDate>Thu, 08 May 2008 19:02:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8472572</guid><dc:creator>Speednet</dc:creator><description>&lt;p&gt;The SQL example above is incorrect. &amp;nbsp;The proper syntax for a wildcard is a percent sign, not an asterisk. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Your example should be: &amp;nbsp;SELECT * FROM CustomerTable WHERE Phone LIKE '206%'&lt;/p&gt;
&lt;p&gt;However, the VB example is correct, because in VB the LIKE operator does use an asterisk for the wildcard.&lt;/p&gt;
</description></item><item><title>re: Converting SQL to LINQ, Part 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx#8473181</link><pubDate>Thu, 08 May 2008 20:46:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8473181</guid><dc:creator>RonO</dc:creator><description>&lt;p&gt;@Speednet: I think you'll find it's all a matter of context. &amp;nbsp;If your database backend is Access, the example *is* correct. &amp;nbsp;If you're using something like SQL Server, Oracle, or MySQL; your syntax is correct. &amp;nbsp;Given how many VB examples are shown as written against an Access databse, I assumed this was the case for the original example. &amp;nbsp;However, considering how prevalent other database systems are, a comment refering to the normal syntax for those systems would have been recommended.&lt;/p&gt;
</description></item><item><title>re: Converting SQL to LINQ, Part 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx#8473374</link><pubDate>Thu, 08 May 2008 21:12:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8473374</guid><dc:creator>RonO</dc:creator><description>&lt;p&gt;@Anthony: The Like operator is exclusive to VB. The specific example using LINQ in C# would be written something akin to*:&lt;/p&gt;
&lt;p&gt;from Contact in CustomerTable&lt;/p&gt;
&lt;p&gt;where Contact.Phone.StartsWith(&amp;quot;206&amp;quot;)&lt;/p&gt;
&lt;p&gt;select Contact;&lt;/p&gt;
&lt;p&gt;If you wanted to perform more complex pattern matching, I'd recommend using the RegEx capabilities.&lt;/p&gt;
&lt;p&gt;* I've never actually written LINQ in C#, but the examples in the VS2008 documentation indicate this syntax is appropriate. &amp;nbsp;Testing this out on your own system is highly recommended. &amp;nbsp;YMMV. &amp;nbsp;Void where prohibited.&lt;/p&gt;
</description></item><item><title>re: Converting SQL to LINQ, Part 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx#8475593</link><pubDate>Fri, 09 May 2008 02:39:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8475593</guid><dc:creator>Speednet</dc:creator><description>&lt;p&gt;@RonO: I guess I assumed that it was SQL server when you said &amp;quot;In SQL, the LIKE keyword...&amp;quot;&lt;/p&gt;
&lt;p&gt;Do people still do Access development, now that SQL Express is so prevalent? &amp;nbsp;(And free.)&lt;/p&gt;
&lt;p&gt;On the subject of the Visual Basic LIKE operator, it is indeed unique to VB (not available in C#). &amp;nbsp;&lt;/p&gt;
&lt;p&gt;LIKE is many times quicker than using a regular expression, so if you have a comparison that is going to be done multiple times, or if speed is urgent, then LIKE should be used instead of RegExp. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is an MSDN article comparing RegExp and LIKE: &amp;nbsp;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms235204.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms235204.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And here is a terrific little blog entry that deals with LIKE vs. RegExp vs. Char(): &amp;nbsp;&lt;a rel="nofollow" target="_new" href="http://www.dotnet2themax.com/blogs/fbalena/PermaLink,guid,53da27bf-b980-4abc-a4e8-a452dc6ceb26.aspx"&gt;http://www.dotnet2themax.com/blogs/fbalena/PermaLink,guid,53da27bf-b980-4abc-a4e8-a452dc6ceb26.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Converting SQL to LINQ, Part 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx#8510392</link><pubDate>Fri, 16 May 2008 03:50:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8510392</guid><dc:creator>VBTeam</dc:creator><description>&lt;p&gt;@Anthony, RonO: &amp;nbsp;It actually is possible to use the LikeOperator in C# if you're determined to do so.&lt;/p&gt;
&lt;p&gt;Lutz Roeder's .NET Reflector tool is very handy for figuring out how to move between VB and C# code. &amp;nbsp;It can be downloaded for free at &lt;a rel="nofollow" target="_new" href="http://www.aisto.com/roeder/dotnet/"&gt;http://www.aisto.com/roeder/dotnet/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The C# equivalent for the code above is:&lt;/p&gt;
&lt;p&gt;from Contact in CustomerTable&lt;/p&gt;
&lt;p&gt;where LikeOperator.LikeString(Contact.Phone, &amp;quot;206*&amp;quot;, CompareMethod.Binary)&lt;/p&gt;
&lt;p&gt;select Contact;&lt;/p&gt;
&lt;p&gt;This would also require adding a reference to Microsoft.VisualBasic (which I realize is a weird thing to do in C#) and adding the following two using statements:&lt;/p&gt;
&lt;p&gt;using Microsoft.VisualBasic;&lt;/p&gt;
&lt;p&gt;using Microsoft.VisualBasic.CompilerServices;&lt;/p&gt;
&lt;p&gt;Of course, why do all this when you can just use VB? ;)&lt;/p&gt;
</description></item><item><title>SQL から LINQ への変換、パート 10: Like (Bill Horst)</title><link>http://blogs.msdn.com/vbteam/archive/2008/05/07/converting-sql-to-linq-part-10-like-bill-horst.aspx#8614893</link><pubDate>Wed, 18 Jun 2008 10:26:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8614893</guid><dc:creator>The Visual Basic Team</dc:creator><description>&lt;p&gt;ここでは、これまでの「 SQL から LINQ への変換 」の投稿をお読みになっていることを前提としています。 LINQ の投稿に関する具体的なリクエストはそれほど多くなかったので、ご提案があれば今からでも歓迎します。&lt;/p&gt;
</description></item></channel></rss>