﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Programming By A Tool &#187; Like</title>
	<atom:link href="http://byatool.com/tag/like/feed/" rel="self" type="application/rss+xml" />
	<link>http://byatool.com</link>
	<description>This is my recorded stumbling through ASP.Net, Framework 3.5, C# 3.0, Ajax, Javascript, and Love.  Stay, learn, destroy.  It's your life.</description>
	<lastBuildDate>Thu, 03 May 2012 17:28:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Speaking of Select</title>
		<link>http://byatool.com/general-coding/speaking-of-select/</link>
		<comments>http://byatool.com/general-coding/speaking-of-select/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 17:46:00 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[Like]]></category>
		<category><![CDATA[Select]]></category>

		<guid isPermaLink="false">http://rockcityghost.wordpress.com/2008/08/22/speaking-of-select/</guid>
		<description><![CDATA[So like Where and other fine Extension methods, Select allows you to either give it a lambda expression like so: List&#60;String&#62; newList = userList.Select(user =&#62; user.Name); Or List&#60;Int32&#62; newList = userList.Select(user =&#62; user.ID); So either you get a list of Names or IDs. What the hell do you care? Well if you are capable of [...]]]></description>
			<content:encoded><![CDATA[<p>So like Where and other fine Extension methods, Select allows you to either give it a lambda expression like so:</p>
<pre>  <span style="color: #00cccc;">List</span>&lt;<span style="color: #00cccc;">String</span>&gt; newList = userList.Select(user =&gt; user.Name);</pre>
<p>Or</p>
<pre><span style="color: #00cccc;">  List</span>&lt;<span style="color: #00cccc;">Int32</span>&gt; newList = userList.Select(user =&gt; user.ID);</pre>
<p>So either you get a list of Names or IDs. What the hell do you care? Well if you are capable of breathing, you should also notice that one list is a list of strings the other a list of integers. What if you wanted a generic select method? Well for starters you would do something like this:</p>
<pre><span style="color: #3333ff;">public</span> <span style="color: #00cccc;">List</span>&lt;<span style="color: #00cccc;">String</span>&gt; SelectFromUserList(<span style="color: #00cccc;">Func</span>&lt;<span style="color: #00cccc;">User</span>, <span style="color: #00cccc;">String</span>&gt; selectMethod, <span style="color: #00cccc;">List</span>&lt;<span style="color: #00cccc;">User</span>&gt; userList)
{
<span style="color: #3333ff;">  return</span> userList.Select(selectMethod).ToList();
}</pre>
<p>Where the select method for a user name would be something like this:</p>
<pre><span style="color: #00cccc;">  List</span>&lt;<span style="color: #00cccc;">String</span>&gt; nameList = SelectFromUserList(currentUser =&gt; currentUser.UserName, userList);</pre>
<p>Sweet&#8230; oh wait, that only works if I want a list strings. Great if I wanted LastName, FirstName, ect but sucks if I wanted an integer ID.</p>
<pre><span style="color: #00cccc;">  List</span>&lt;<span style="color: #00cccc;">String</span>&gt; nameList = SelectFromUserList(currentUser =&gt; currentUser.UserID, userList); <span style="color: #009900;">//BOOM</span></pre>
<p>But wait, you can do that!</p>
<pre><span style="color: #3333ff;">public</span> <span style="color: #00cccc;">List</span>&lt;K&gt; SelectUserNameList&lt;K&gt;(<span style="color: #00cccc;">Func</span>&lt;<span style="color: #00cccc;">User</span>, K&gt; selectMethod, <span style="color: #00cccc;">List</span>&lt;<span style="color: #00cccc;">User</span>&gt; userList)
{
<span style="color: #3333ff;">  return</span> userList.Select(selectMethod).ToList();
}</pre>
<p>Aw snap, now I can get a list of anything I want, well at least a one type, one dimensional array. By the way, this is the first step in probably a series of posts that will end up with a much cleaner way of doing this.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/general-coding/speaking-of-select/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Like versus Contains in Linq</title>
		<link>http://byatool.com/net-issues/like-versus-contains/</link>
		<comments>http://byatool.com/net-issues/like-versus-contains/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 15:52:00 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[.Net Issues]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Contains]]></category>
		<category><![CDATA[Like]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://rockcityghost.wordpress.com/2008/07/22/like-versus-contains/</guid>
		<description><![CDATA[So have to figure this one out. Say you have: private static Expression&#60;Func&#60;User, Boolean&#62;&#62; WhereLikeFirstNameLastNameUserName(String name) { return currentUser =&#62; SqlMethods.Like(currentUser.UserName, "%" + name + "%") &#124;&#124; SqlMethods.Like(currentUser.FirstName, "%" + name + "%") &#124;&#124; SqlMethods.Like(currentUser.LastName, "%" + name + "%"); } And private static Expression &#60;Func&#60;User, Boolean&#62;&#62; WhereLikeFirstNameLastNameUserNameWithoutLike(String name) { return currentUser =&#62; currentUser.UserName.Contains(name) &#124;&#124; [...]]]></description>
			<content:encoded><![CDATA[<p>So have to figure this one out. Say you have:</p>
<pre><span style="color: #3333ff;">private static</span> <span style="color: #00cccc;">Expression</span>&lt;<span style="color: #00cccc;">Func</span>&lt;<span style="color: #00cccc;">User</span>, <span style="color: #00cccc;">Boolean</span>&gt;&gt; WhereLikeFirstNameLastNameUserName(<span style="color: #00cccc;">String </span>name)
{
 <span style="color: #3333ff;"> return </span>currentUser =&gt; <span style="color: #00cccc;">SqlMethods</span>.Like(currentUser.UserName, <span style="color: #cc0000;">"%"</span> + name + <span style="color: #cc0000;">"%"</span>)
  || <span style="color: #00cccc;">SqlMethods</span>.Like(currentUser.FirstName, <span style="color: #cc0000;">"%"</span> + name + <span style="color: #cc0000;">"%"</span>)
  || <span style="color: #00cccc;">SqlMethods</span>.Like(currentUser.LastName, <span style="color: #cc0000;">"%"</span> + name + <span style="color: #cc0000;">"%"</span>);
}</pre>
<p>And</p>
<pre><span style="color: #3333ff;">private static</span> <span style="color: #00cccc;">Expression </span>&lt;<span style="color: #00cccc;">Func</span>&lt;<span style="color: #00cccc;">User</span>, <span style="color: #00cccc;">Boolean</span>&gt;&gt; WhereLikeFirstNameLastNameUserNameWithoutLike(<span style="color: #00cccc;">String </span>name)
{
  <span style="color: #3333ff;">return </span>currentUser =&gt; currentUser.UserName.Contains(name)
  || currentUser.FirstName.Contains(name)
  || currentUser.LastName.Contains(name);
}</pre>
<p>The first one should look familiar, its part of the &#8220;dynamic&#8221; linq stuff I&#8217;ve been posting. Now guess which one gives me this SQL when profiled:</p>
<pre><span style="color: #3333ff;">exec </span><span style="color: #660000;">sp_executesql</span> N
<span style="color: #ff0000;">'SELECT</span>
<span style="color: #ff0000;"> [t0].[UserID],</span>
<span style="color: #ff0000;"> [t0].[FirstName],</span>
<span style="color: #ff0000;"> [t0].[LastName],</span>
<span style="color: #ff0000;"> [t0].[Password],</span>
<span style="color: #ff0000;"> [t0].[UserName],</span>
<span style="color: #ff0000;"> [t0].[UserTypeID]</span>
<span style="color: #ff0000;">FROM</span>
<span style="color: #ff0000;"> [dbo].[User] AS [t0]</span>
<span style="color: #ff0000;">WHERE</span>
<span style="color: #ff0000;"> ([t0].[UserName] LIKE @p0)</span>
<span style="color: #ff0000;">OR</span>
<span style="color: #ff0000;"> ([t0].[FirstName] LIKE @p1)</span>
<span style="color: #ff0000;">OR</span>
<span style="color: #ff0000;"> ([t0].[LastName] LIKE @p2)</span>
<span style="color: #ff0000;">ORDER BY</span>
<span style="color: #ff0000;"> [t0].[UserName]'</span>,

N<span style="color: #ff0000;">'@p0 varchar(3),</span>
<span style="color: #ff0000;"> @p1 nvarchar(3),</span>
<span style="color: #ff0000;"> @p2 nvarchar(3)'</span>,
 @p0=<span style="color: #ff0000;">'%s%'</span>,
 @p1=N<span style="color: #ff0000;">'%s%'</span>,
 @p2=N<span style="color: #ff0000;">'%s%'</span></pre>
<p>If you answered both, you are correct or you looked ahead for the answer and therefore are a tool. Now which do you think that&#8230;</p>
<pre>query.ToList()</pre>
<p>Produces the correct list? If you answered Contains, then you are correct again. If you are a tool, you probably looked ahead again&#8230;</p>
<p>Why is this? I HAVE NO IDEA&#8230; Something I have to look into for sure.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/net-issues/like-versus-contains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

