<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:a10="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
	<channel>
		<title>SingingEels : Development Community &amp; Resource</title>
		<link>http://www.singingeels.com/</link>
		<description>SingingEels.com is a fresh and new article site dedicated to web programming in ASP.NET, general architecture, web and coding standards, SQL and security.</description>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/SingingEelsBlogs" type="application/rss+xml" /><item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/07/18/Fluent_Interfaces_to_XML_My_Example_of_Fluent_Interfaces.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/339296551/Fluent_Interfaces_to_XML_My_Example_of_Fluent_Interfaces.aspx</link>
			<author>Timothy Khouri</author>
			<category>Standards</category>
			<title>Fluent Interfaces to XML (My Example of Fluent Interfaces)</title>
			<description>&lt;p&gt;Recently I've been talking to a &lt;a href="http://www.lostintangent.com/" rel="nofollow"&gt;developer friend of mine&lt;/a&gt; about &lt;a href="http://www.martinfowler.com/bliki/FluentInterface.html" rel="nofollow"&gt;Fluent Interfaces&lt;/a&gt;, due to a recent posting from &lt;a href="http://www.managed-world.com/2008/07/04/BuildingAFluentInterfaceForMEF.aspx" rel="nofollow"&gt;Jason Olson&lt;/a&gt;... (yes, I realize I just put 3 links in a single sentence... I apologize).&lt;/p&gt;

&lt;p&gt;Anyway, at first I brushed it off as yet another 'neat' thing that the development community is doing. But in some "quiet time", I decided to read up on what this really meant, and how it could help me as a developer. I have to say, I'm in love!&lt;/p&gt;

&lt;p&gt;Within about 30 minutes, I understood what they were saying, and devised an example to myself to see if I really got it. Now, it could be that I missed the point 100% and that I'm just doing "method chaining", but hopefully, this is my rendition of a fluent interface to XML!&lt;/p&gt;

&lt;h3&gt;Why I Chose XML
&lt;/h3&gt;&lt;p&gt;First, I have to explain that I chose to write a fluent interface over XML because I hate working with XML in the .NET framework. Now, I will be fair and mention that LINQ to XML has made this a lot easier (and cleaner)... but I still hate it... plus I wanted to pick an easy example that I could explore.&lt;/p&gt;

&lt;p&gt;Basically, I've only added functionality to write xml elements, xml attributes, text nodes and complex types. So, before I show you the code that I wrote to make the fluent interface class itself, I'll show you how I used it and what the result is. So here's my own code that I just came up with:&lt;/p&gt;

&lt;div class="CodeBlock C#"&gt;&lt;span class="KeyWord"&gt;static&lt;/span&gt; &lt;span class="KeyWord"&gt;void&lt;/span&gt; Main(&lt;span class="KeyWord"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;
{&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;string&lt;/span&gt; result = FluentInterfaceForXml&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Element(&lt;span class="String"&gt;"root"&lt;/span&gt;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.WithNode(&lt;span class="String"&gt;"person"&lt;/span&gt;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.WithAttribute(&lt;span class="String"&gt;"firstName"&lt;/span&gt;, &lt;span class="String"&gt;"Timothy"&lt;/span&gt;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.WithAttribute(&lt;span class="String"&gt;"lastName"&lt;/span&gt;, &lt;span class="String"&gt;"Khouri"&lt;/span&gt;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.WithNode(&lt;span class="String"&gt;"person"&lt;/span&gt;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.WithAttribute(&lt;span class="String"&gt;"firstName"&lt;/span&gt;, &lt;span class="String"&gt;"Bob"&lt;/span&gt;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.WithAttribute(&lt;span class="String"&gt;"lastName"&lt;/span&gt;, &lt;span class="String"&gt;"Dole"&lt;/span&gt;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.WithComplexType&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FluentInterfaceForXml&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Element(&lt;span class="String"&gt;"person"&lt;/span&gt;)&lt;br /&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;.WithAttribute(&lt;span class="String"&gt;"firstName"&lt;/span&gt;, &lt;span class="String"&gt;"Sam"&lt;/span&gt;)&lt;br /&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;.WithAttribute(&lt;span class="String"&gt;"lastName"&lt;/span&gt;, &lt;span class="String"&gt;"Cooke"&lt;/span&gt;)&lt;br /&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;.WithNode(&lt;span class="String"&gt;"skill"&lt;/span&gt;)&lt;br /&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;.WithAttribute(&lt;span class="String"&gt;"singing"&lt;/span&gt;, &lt;span class="String"&gt;"100"&lt;/span&gt;)&lt;br /&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;.WithAttribute(&lt;span class="String"&gt;"soul"&lt;/span&gt;, &lt;span class="String"&gt;"100"&lt;/span&gt;)&lt;br /&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;.WithAttribute(&lt;span class="String"&gt;"awesomeness"&lt;/span&gt;, &lt;span class="String"&gt;"100"&lt;/span&gt;)&lt;br /&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;.WithNode(&lt;span class="String"&gt;"favoriteQuote"&lt;/span&gt;)&lt;br /&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;.WithText(&lt;span class="String"&gt;"I was born by the river!"&lt;/span&gt;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.ToString();&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;Console.WriteLine(result);&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;... and here's what the above results in:&lt;/p&gt;

&lt;img src="./Articles/UserImage.aspx?ImageID=2acac9c4-d1ce-4f43-a4ef-d14694164624" alt="Example of a fluent interface to XML in a Console application" title="Example of a fluent interface to XML in a Console application" /&gt; &lt;/p&gt;

&lt;p&gt;That's some pretty hot code right there :)&lt;/p&gt;

&lt;h3&gt;My Fluent Interface Class
&lt;/h3&gt;&lt;p&gt;Hopefully you can understand what a fluent interface is now... unless I missed the point altogether :) So, you might be curious as to the code wrote to make this all happen... and it's simple really. Basically, I just made a simple C# class that has an XML document inside of it as a private field, and then when you call the ".WithNode" or ".WithAttribute" methods, I do the appropriate code that would give the desired results and return "this" back to the caller.&lt;/p&gt;

&lt;p&gt;Here's the entire project. Take a look for yourself: &lt;a href="./Articles/UserFile.aspx?FileID=d04d4c51-b352-4654-9118-c52898e76e75"&gt;SingingEels_FluentInterface_ForXML.zip&lt;/a&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/339296551" height="1" width="1"/&gt;</description>
			<pubDate>Fri, 18 Jul 2008 13:41:43 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/07/18/Fluent_Interfaces_to_XML_My_Example_of_Fluent_Interfaces.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/06/30/Silverlight_2_Beta_2__Image_Source_Bug_With_QueryString_Parameters.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/323193108/Silverlight_2_Beta_2__Image_Source_Bug_With_QueryString_Parameters.aspx</link>
			<author>Timothy Khouri</author>
			<category>Silverlight</category>
			<title>Silverlight 2 Beta 2 - Image Source Bug With QueryString Parameters</title>
			<description>&lt;p&gt;Recently, I've been working on an update to a feature for SingingEels while at the same time writing an article on how to build an "image manager" using Silverlight. Because we store images (and thumbnails) in our database, we retrieve them via their ID as a query string parameter. Example:&lt;/p&gt;

&lt;div class="CodeBlock asp"&gt;&amp;lt;&lt;span class="Tag"&gt;a&lt;/span&gt; &lt;span class="Key"&gt;href&lt;/span&gt;&lt;span class="Value"&gt;="Images.aspx?ID=1234"&lt;/span&gt; /&amp;gt;&lt;/div&gt;

&lt;p&gt;This is some very simple code, and there are probably a million articles on how to dynamically retrieve images from a database and display them in a browser.&lt;/p&gt;

&lt;p&gt;So, as I was converting our existing functionality into a Silverlight application, I ran into a strange bug. As of right now (Silverlight 2 Beta 2), if you put a query string property in the 'Source' of an 'Image', it'll get ignored. So, if this is your XAML:&lt;/p&gt;

&lt;div class="CodeBlock xml"&gt;&amp;lt;&lt;span class="Tag"&gt;Image&lt;/span&gt; &lt;span class="Key"&gt;Source&lt;/span&gt;&lt;span class="Value"&gt;="Images.aspx?ID=1234"&lt;/span&gt; /&amp;gt;&lt;/div&gt;

&lt;p&gt;Then instead of sending a request to the entire URI, Silverlight chops off everything from the quetion mark onward. Here's a screen-shot of what actually came accross the wire. Notice that the URL doesn't include the query string (as if Silverlight is intentionally truncating it):&lt;/p&gt;

&lt;img src="./Articles/UserImage.aspx?ImageID=9896e291-460e-4507-bec8-e1db90e45d9b" alt="Silverlight 2 beta 2 bug with image source - truncating query string" title="Silverlight 2 beta 2 bug with image source - truncating query string" /&gt;

&lt;p&gt;Now, to show you that I'm not crazy (and how I got around this issue for my testing purposes). I changed my XAML a little bit to be the following:&lt;/p&gt;

&lt;div class="CodeBlock asp"&gt;&amp;lt;&lt;span class="Tag"&gt;a&lt;/span&gt; &lt;span class="Key"&gt;href&lt;/span&gt;&lt;span class="Value"&gt;="Images.aspx/ID=1234"&lt;/span&gt; /&amp;gt;&lt;/div&gt;

&lt;p&gt;With this simple change in my URL, notice the URL that is being addressed:&lt;/p&gt;

&lt;img src="./Articles/UserImage.aspx?ImageID=c33b4e03-64ba-40c5-91b2-301f4bdc63e0" alt="Silverlight 2 beta 2 bug with image source - slash instead of question mark" title="Silverlight 2 beta 2 bug with image source - slash instead of question mark" /&gt;

&lt;h3&gt;Fix The Bug!
&lt;/h3&gt;&lt;p&gt;My intention for bringing this out isn't to slam Silverlight in any way. It's going to be a great product, and I'm loving it even now. My hope is that someone reads this (who is on the SL dev team), and says "oh yeah, I forgot to fix that"... and then hopefully... they do fix it before launch :)&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/323193108" height="1" width="1"/&gt;</description>
			<pubDate>Mon, 30 Jun 2008 05:06:36 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/06/30/Silverlight_2_Beta_2__Image_Source_Bug_With_QueryString_Parameters.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/06/16/ASPNET_MVC__Issue_with_CSS_Class_Name_on_ActionLinks.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/314166686/ASPNET_MVC__Issue_with_CSS_Class_Name_on_ActionLinks.aspx</link>
			<author>Timothy Khouri</author>
			<category>ASP.NET</category>
			<title>ASP.NET MVC - Issue with CSS Class Name on ActionLinks</title>
			<description>&lt;p&gt;I've been getting into ASP.NET MVC recently, and I have to say, it's a beautiful thing. Being that it's incredibly new and beta (currently preview 3 is out), there are a few bugs that I've run into.&lt;/p&gt;

&lt;p&gt;This one in particular has to do with how to add custom HTML attributes to your ActionLinks (which is basically a link to an MVC "page"). The method that you call to create a link is basically this:&lt;/p&gt;

&lt;div class="CodeBlock asp"&gt;&lt;span class="InlineAsp"&gt;&amp;lt;%&lt;/span&gt;&lt;span class="AspKey"&gt;=&lt;/span&gt; Html.ActionLink&amp;lt;&lt;span class=&lt;span class="String"&gt;"Tag"&lt;/span&gt;&gt;MyController&lt;/span&gt;&amp;gt;(c =&amp;gt; c.SomeAction(), &lt;span class="String"&gt;"Link Text"&lt;/span&gt; &lt;span class="InlineAsp"&gt;%&amp;gt;&lt;/span&gt;&lt;/div&gt;

&lt;p&gt;This would build a link to the 'SomeAction' view on the MyController... controller :) Now, there are ways to build action links that are a little easier on the eyes, but I'm using this particular overload to show how to add HTML attributes to your link.&lt;/p&gt;

&lt;p&gt;So, if you wanted to do some inline CSS, you would change the above code to the following:&lt;/p&gt;

&lt;div class="CodeBlock asp"&gt;&lt;span class="InlineAsp"&gt;&amp;lt;%&lt;/span&gt;&lt;span class="AspKey"&gt;=&lt;/span&gt; Html.ActionLink&amp;lt;&lt;span class=&lt;span class="String"&gt;"Tag"&lt;/span&gt;&gt;MyController&lt;/span&gt;&amp;gt;(c =&amp;gt; c.SomeAction(), &lt;span class="String"&gt;"Link Text"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;new&lt;/span&gt; { style = &lt;span class="String"&gt;"color: #f00;"&lt;/span&gt; } &lt;span class="InlineAsp"&gt;%&amp;gt;&lt;/span&gt;&lt;/div&gt;

&lt;p&gt;ASP.NET MVC will automatically parse the "object" parameter at the end there and reflect all properties, then it will add them to your link. So the above code would build a link that looks something like this:&lt;/p&gt;

&lt;div class="CodeBlock asp"&gt;&amp;lt;&lt;span class="Tag"&gt;a&lt;/span&gt; &lt;span class="Key"&gt;href&lt;/span&gt;&lt;span class="Value"&gt;="/MyController/SomeAction"&lt;/span&gt; &lt;span class="Key"&gt;style&lt;/span&gt;&lt;span class="Value"&gt;="color: #f00;"&lt;/span&gt;&amp;gt;Link Text&amp;lt;&lt;span class="Tag"&gt;/a&lt;/span&gt;&amp;gt;&lt;/div&gt;

&lt;h3&gt;Where ASP.NET MVC Loses Me
&lt;/h3&gt;&lt;p&gt;This approach above seems very 'code cowboy' to me. There is no reason why the last paramter doesn't simply take a params array of name value pairs, or a dictionary, or something like that. Instead, we are now bound to only use HTML attributes that are valid C# (or VB if you're using that language) property names!&lt;/p&gt;

&lt;p&gt;I realize this may seem a little dramatic... but while building my navigation, I wanted to add a simple "class='selected'" attribute to my link... and guess what... "class" is a key-word in C#. So this:&lt;/p&gt;

&lt;div class="CodeBlock asp"&gt;&lt;span class="InlineAsp"&gt;&amp;lt;%&lt;/span&gt;&lt;span class="AspKey"&gt;=&lt;/span&gt; Html.ActionLink&amp;lt;&lt;span class=&lt;span class="String"&gt;"Tag"&lt;/span&gt;&gt;MyController&lt;/span&gt;&amp;gt;(c =&amp;gt; c.SomeAction(), &lt;span class="String"&gt;"Link Text"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;new&lt;/span&gt; { &lt;span class="KeyWord"&gt;class&lt;/span&gt; = &lt;span class="String"&gt;"selected"&lt;/span&gt; } &lt;span class="InlineAsp"&gt;%&amp;gt;&lt;/span&gt;&lt;/div&gt;

&lt;p&gt;Doesn't compile, and now I'm sad.&lt;/p&gt;

&lt;h3&gt;Bear With Me
&lt;/h3&gt;&lt;p&gt;I realize the above complaint is minor... and I am really starting to like MVC, but this just shows me it's not a 100% product yet. I'm excited to see where it goes :)&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/314166686" height="1" width="1"/&gt;</description>
			<pubDate>Mon, 16 Jun 2008 14:49:02 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/06/16/ASPNET_MVC__Issue_with_CSS_Class_Name_on_ActionLinks.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/06/05/My_Bad_Coding_Habits_Thanks_LINQ_to_SQL.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/305766444/My_Bad_Coding_Habits_Thanks_LINQ_to_SQL.aspx</link>
			<author>Timothy Khouri</author>
			<category>LINQ</category>
			<title>My Bad Coding Habits, Thanks LINQ to SQL!</title>
			<description>&lt;h3&gt;Don't Forget Performance!
&lt;/h3&gt;&lt;p&gt;I have to start off by saying that I'm not seriously blaming LINQ to SQL for my bad coding habits, but I will mention that due to all these great technologies that just do stuff for us, we sometimes forget to check for things like performance. Sometimes I take for granted that .NET is ultimately just running code that some mere mortal programmer wrote.&lt;/p&gt;

&lt;p&gt;As a result, I just assume that anything that happens outside of *my* code will run at infinite speeds. So, the other day I was reprimanding (not really, but I was semi-lecturing) one of my senior developers for hitting the SQL server in a for loop. Now, to be fair, he's new to LINQ to SQL, and didn't realize that this...&lt;/p&gt;

&lt;div class="CodeBlock C#"&gt;&lt;span class="KeyWord"&gt;foreach&lt;/span&gt; (Task t &lt;span class="KeyWord"&gt;in&lt;/span&gt; myTasks) {&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;if&lt;/span&gt; (t.BillingEntries.Count() &amp;gt; 0) {&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// &lt;span class="KeyWord"&gt;this&lt;/span&gt; &lt;span class="KeyWord"&gt;is&lt;/span&gt; just an example&lt;/span&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;...was going back to the database over and over again :) Just for clarification, the "BillingEntries" property up there is linked from another SQL table.&lt;/p&gt;

&lt;p&gt;It wasn't difficult to fix the problem. All we needed to do was get the "count" information in a single hit to the DB, store it in a dictionary, and use it in the for loop, instead of hitting the DB in the for loop.&lt;/p&gt;

&lt;h3&gt;Where I Had To Eat My Words
&lt;/h3&gt;&lt;p&gt;So, yesterday, as I was updating some styling on the site (SingingEels.com), I realized that some pages were taking a long time to load (from my local machine). A few pages were taking upward of 10 seconds each... and that's when I realized!&lt;/p&gt;

&lt;p&gt;My web server and SQL server are physically next to each other (I think in Colorado, USA), but I live in Florida. So, when I was developing locally, and my web app hit my SQL server in a for loop... well, you get the idea.&lt;/p&gt;

&lt;p&gt;Needless to say, I've since then been optimizing the site, and I've included a "server load time" number at the bottom of the site. The moral of the story is, don't forget to check your app for performance issues.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/305766444" height="1" width="1"/&gt;</description>
			<pubDate>Thu, 05 Jun 2008 20:19:17 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/06/05/My_Bad_Coding_Habits_Thanks_LINQ_to_SQL.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/05/20/Im_Loving_InfoQ_an_Online_Development_Community.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/295484935/Im_Loving_InfoQ_an_Online_Development_Community.aspx</link>
			<author>Timothy Khouri</author>
			<title>I'm Loving InfoQ (an Online Development Community)</title>
			<description>&lt;p&gt;Recently, a friend of mine turned me on to &lt;a href="http://www.infoq.com/" rel="nofollow"&gt;InfoQ.com&lt;/a&gt;, and I've found myself back there again via a few Google searches. I'm starting to really like this site for their interviews.&lt;/p&gt;

&lt;p&gt;I've &lt;a href="http://www.singingeels.com/Blogs/Nullable/2008/05/13/The_Most_Amazing_Interview_Ive_Seen__Pete_Lacey_on_REST.aspx" rel="nofollow"&gt;already posted&lt;/a&gt; about a really great inverview with Pete Lacey on REST.&lt;/p&gt;

&lt;p&gt;My Google searching (researching DI frameworks, Microsoft's "Unity" in particular for various reasons) came up with this great article: "&lt;a href="http://www.infoq.com/news/2008/04/microsoft-unity" rel="nofollow"&gt;Microsoft Unity Dependency Injection Application Block Released&lt;/a&gt;".&lt;/p&gt;

&lt;p&gt;And, by visiting the front page, I've found this hot topic (that I'm involved with, and have contributed to): &lt;a href="http://www.infoq.com/news/2008/05/Entity-Framework-Sparks-a-Debate" rel="nofollow"&gt;The ADO.NET Entity Framework Sparks a Debate&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All in all, this is a great site and I will certainly give it priority in my searches in the future.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/295484935" height="1" width="1"/&gt;</description>
			<pubDate>Tue, 20 May 2008 17:01:03 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/05/20/Im_Loving_InfoQ_an_Online_Development_Community.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/05/13/The_Most_Amazing_Interview_Ive_Seen__Pete_Lacey_on_REST.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/295484936/The_Most_Amazing_Interview_Ive_Seen__Pete_Lacey_on_REST.aspx</link>
			<author>Timothy Khouri</author>
			<category>ADO.NET</category>
			<title>The Most Amazing Interview I've Seen - Pete Lacey on REST</title>
			<description>&lt;p&gt;I just finished watching &lt;a href="http://www.infoq.com/interviews/pete-lacey-rest" rel="nofollow"&gt;Pete Lacey talking about REST and web services&lt;/a&gt; for the past 30 minutes or so. As I am invested in "Astoria" (now ADO.NET Data Services), I've gotten into Atom, Atom Pub, HTTP and REST a lot more, but a lot of it still didn't 'really click' until I watched that.&lt;/p&gt;

&lt;p&gt;If you have some idea about Astoria (from Microsoft), or REST, and you want to have someone put all those pieces in your head together to make a beautiful puzzel painting... watch that video.&lt;/p&gt;

&lt;p&gt;Some of my favorite highlights from that video:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pete's explaination of how WS* can't get away from 'tight-coupling', and how REST solves that.&lt;/li&gt;
&lt;li&gt;"Every peice of information has it's own URI" - REST in one sentense.&lt;/li&gt;
&lt;li&gt;"Everybody and everything is free to do a GET" - This will make sense to you when you watch the video :)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I can't say enough how groundbreaking that was to me. And, just to prove how much of a nerd I am, my friend (who sent me the link to that video) and I have been coming up with awesome REST T-Shirt ideas. Here are a few:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"I GET REST" - perhaps with "And I POST too" on the back?&lt;/li&gt;
&lt;li&gt;"POST it a REST" - instead of the phrase 'give it a rest'.&lt;/li&gt;
&lt;li&gt;"Ex-WS*ian gone RESTafarian" - If this doesn't make sense to you, it's because you weren't using a Jamaican accent when you read it :)&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/295484936" height="1" width="1"/&gt;</description>
			<pubDate>Tue, 13 May 2008 19:26:10 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/05/13/The_Most_Amazing_Interview_Ive_Seen__Pete_Lacey_on_REST.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/04/20/Site_Updates_Bug_Fixes_and_Syndication_in_NET_35.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/295484937/Site_Updates_Bug_Fixes_and_Syndication_in_NET_35.aspx</link>
			<author>Timothy Khouri</author>
			<category>ASP.NET</category>
			<title>Site Updates, Bug Fixes and Syndication in .NET 3.5</title>
			<description>&lt;h3&gt;Minor Bug Fixes
&lt;/h3&gt;&lt;p&gt;There have been a few bugs and glitches that I've noticed since the recent rewrite. For starters, the Blogs RSS page wasn't linking to the blog posts. They were correctly displaying most recent blog entries, but the link was broken and would simply take you back to the front page of the site.&lt;/p&gt;

&lt;p&gt;There was also a strange bug with the categories selector when writing an article. If you would edit your aritcle, and not change your selection of categories, then the next time you saved, the categories were blank... like I said, weird bug, but it's fixed now.&lt;/p&gt;

&lt;h3&gt;Minor Updates
&lt;/h3&gt;&lt;p&gt;Also, since I've recently learned about the System.ServiceModel.Syndication namespace, I've changed the RSS code to use these new classes for sending out the RSS feeds. Because of it, there is a new feature (well, not new, but I wasn't doing it before). Now the article's (or blog post's) categories are being sent too in the feed. This lets you sort or filter by a the category in your favorite RSS viewer!&lt;/p&gt;

&lt;p&gt;Here's a snippet of the code that I'm using now. It's offers some easy RSS abilities in .NET:&lt;/p&gt;

&lt;h3&gt;System.ServiceModel.Syndication
&lt;/h3&gt;&lt;div class="CodeBlock C#"&gt;&lt;span class="Comment"&gt;// This &lt;span class="KeyWord"&gt;is&lt;/span&gt; &lt;span class="KeyWord"&gt;in&lt;/span&gt; the System.ServiceModel.Web dll. So you'll&lt;/span&gt;&lt;span class="Comment"&gt;&lt;br /&gt;
// have to &lt;span class="KeyWord"&gt;add&lt;/span&gt; a reference to it &lt;span class="KeyWord"&gt;in&lt;/span&gt; your .NET 3.5 web project.&lt;/span&gt;&lt;br /&gt;
&lt;span class="KeyWord"&gt;using&lt;/span&gt; System.ServiceModel.Syndication;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="KeyWord"&gt;public&lt;/span&gt; partial &lt;span class="KeyWord"&gt;class&lt;/span&gt; MyRssPage : ContentPage&lt;br /&gt;
{&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;protected&lt;/span&gt; &lt;span class="KeyWord"&gt;override&lt;/span&gt; &lt;span class="KeyWord"&gt;void&lt;/span&gt; OnInit(EventArgs e)&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;{&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// This isn't required, but I &lt;span class="KeyWord"&gt;do&lt;/span&gt; it anyway.&lt;/span&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;this&lt;/span&gt;.Response.AppendHeader(&lt;span class="String"&gt;"content-type"&lt;/span&gt;, &lt;span class="String"&gt;"application/xml"&lt;/span&gt;);&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Make a list of the items that will be &lt;span class="KeyWord"&gt;in&lt;/span&gt; the feed.&lt;/span&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;List&amp;lt;SyndicationItem&amp;gt; feedItems = &lt;span class="KeyWord"&gt;new&lt;/span&gt; List&amp;lt;SyndicationItem&amp;gt;();&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Add items to my RSS feed. This will probably be selected&lt;/span&gt;&lt;span class="Comment"&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// &lt;span class="KeyWord"&gt;from&lt;/span&gt; a database &lt;span class="KeyWord"&gt;in&lt;/span&gt; real life.&lt;/span&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;feedItems.Add(&lt;span class="KeyWord"&gt;new&lt;/span&gt; SyndicationItem(&lt;span class="String"&gt;"Item One Title"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="String"&gt;"Item one content here. &amp;lt;b&amp;gt;HTML Tags&amp;lt;/b&amp;gt; are ok!"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;new&lt;/span&gt; Uri(&lt;span class="String"&gt;"http://www.singingeels.com/ItemOne.aspx"&lt;/span&gt;)));&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Create the feed &lt;span class="KeyWord"&gt;object&lt;/span&gt; with some simple parameters.&lt;/span&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SyndicationFeed feed = &lt;span class="KeyWord"&gt;new&lt;/span&gt; SyndicationFeed(&lt;span class="String"&gt;"My RSS Feed!"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="String"&gt;"My site description!!!"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;new&lt;/span&gt; Uri(&lt;span class="String"&gt;"http://www.singingeels.com/RSS.aspx"&lt;/span&gt;),&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;feedItems);&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Now to send it &lt;span class="KeyWord"&gt;out&lt;/span&gt; to the browser!&lt;/span&gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XmlWriterSettings feedWriterSettings = &lt;span class="KeyWord"&gt;new&lt;/span&gt; XmlWriterSettings();&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;feedWriterSettings.Indent = &lt;span class="KeyWord"&gt;true&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;feedWriterSettings.IndentChars = "\t";&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XmlWriter feedWriter = XmlWriter.Create(&lt;span class="KeyWord"&gt;this&lt;/span&gt;.Response.OutputStream, feedWriterSettings);&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;feed.SaveAsRss20(feedWriter);&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;feedWriter.Close();&lt;br /&gt;
&lt;br /&gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;this&lt;/span&gt;.Response.End();&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;Of course, you don't have to indent the XML either, but I like my source to look good :) The more I look into .NET 3.5, the more I love it!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/295484937" height="1" width="1"/&gt;</description>
			<pubDate>Sun, 20 Apr 2008 20:07:23 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/04/20/Site_Updates_Bug_Fixes_and_Syndication_in_NET_35.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/04/05/Silverlight_2_Beta_1__Online_Game_and_the_Pain_it_Caused.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/295484938/Silverlight_2_Beta_1__Online_Game_and_the_Pain_it_Caused.aspx</link>
			<author>Timothy Khouri</author>
			<category>Silverlight</category>
			<title>Silverlight 2 Beta 1 - Online Game and the Pain it Caused</title>
			<description>&lt;h3&gt;The Good News
&lt;/h3&gt;&lt;p&gt;First off, I have to say that I have successfully made an "online video game", with Silverlight as the game client. I can't stress enough how overly difficult this was, and how many "the right way" paths I went down that completely failed.&lt;/p&gt;

&lt;h3&gt;Silverlight 2 Beta 1 WCF Issues
&lt;/h3&gt;&lt;p&gt;As of right now (April 5th 2008 at 11:31 PM) as I am writing this blog post, the Silverlight 2 Beta 1 that is out doesn't support "connected" WCF functionality. What I mean by this is that, while you *can* consume WCF web services, you must use basicHttp binding, which means that you lose all ability to have required sessions.&lt;/p&gt;

&lt;p&gt;Hopefully this will be addressed when the full version is out. But as it stands right now, no duplex WCF support and no sessioned WCF support.&lt;/p&gt;

&lt;h3&gt;Silverlight 2 Beta 1 Threading Issues
&lt;/h3&gt;&lt;p&gt;Now, I will eventually tell you how I got this to work, but first you have to understand that there was a lot of pain that needs to be resolved. When I finally got connecting to my server and receiving useful data to my Silverlight app, I was ready to add "players" to my screen... then CRASH!&lt;/p&gt;

&lt;p&gt;Silverlight 2 Beta 1 doesn't have a way for you to update the UI at all from another thread. So, that means that using any thread other than the main thread (which includes WCF or TCP sockets) to create or update your UI, it will absolutely fail. Also, there is no "Page.Invoke" method to call your needed code back on the main UI thread as there is in Windows Forms programming.&lt;/p&gt;

&lt;h3&gt;Ultimately, Good Results = Good Results
&lt;/h3&gt;&lt;p&gt;While I am disappointed in the methods I had to employ to get here, I have to show you my awesome results:&lt;/p&gt;

&lt;img src="./Articles/UserImage.aspx?ImageID=d777ae36-3532-4ca3-b94c-0280561c46ed" alt="Silverlight 2 Beta 1 - Online Game" title="Silverlight 2 Beta 1 - Online Game" /&gt;

&lt;p&gt;Now, this may not look like much, but these are four browser windows running Silverlight applications that ACTUALLY CONNECTED to my C# Windows Console application via TCP sockets, and was displaying my "game" objects on the screen.&lt;/p&gt;

&lt;p&gt;As you clicked on the Silverlight page, it sent a command across the wire to the server and the little red circles were moving around!&lt;/p&gt;

&lt;p&gt;I'll be going to bed now, but soon I'll be writing a "make your own MMORPG video game in Silverlight" article.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/295484938" height="1" width="1"/&gt;</description>
			<pubDate>Sat, 05 Apr 2008 21:45:06 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/04/05/Silverlight_2_Beta_1__Online_Game_and_the_Pain_it_Caused.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/03/26/Dynamic_LINQ_OrderBy_using_String_Names.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/295484939/Dynamic_LINQ_OrderBy_using_String_Names.aspx</link>
			<author>Timothy Khouri</author>
			<category>LINQ</category>
			<title>Dynamic LINQ OrderBy using String Names!</title>
			<description>&lt;h3&gt;Quick Overview of LINQ and Lambda Expressions
&lt;/h3&gt;&lt;p&gt;LINQ is a new enhancement to the .NET framework (version 3.5 and up) that gives powerful query capabilities against any enumerable object. This means that no matter what the data source (whether SQL, XML, or objects such as a generic list or ArrayList) you can do things like sorting (OrderBy), selecting, joining etc.&lt;/p&gt;

&lt;p&gt;If you're not already familiar with LINQ, then you can &lt;a href="http://www.singingeels.com/Articles/Learn_The_Basics_Of_LINQ.aspx" rel="nofollow"&gt;Learn the Basics of LINQ&lt;/a&gt; from that article. Also, to appreciate this new gem that I discovered (actually, I've been trying to do this since I first started using LINQ), you'll need to &lt;a href="http://www.singingeels.com/Blogs/Nullable/2007/09/27/LINQ_Lamda_and_Extension_Methods_Work_Together.aspx" rel="nofollow"&gt;understand lambda expressions with LINQ&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;How To Sort using LINQ and Lamdba
&lt;/h3&gt;&lt;p&gt;First, let's look at a quick example of a data source that you would possibly want to sort, perhaps in a GridView. For the sake of simplicity, I'm just going to populate a generic list in code. If the code that I'm using looks funny, it's probably because you're not familiar with automatic properties (a new C# 3 only feature), lambda (a new language feature in C# 3 and VB9) or anonymous types.&lt;/p&gt;

&lt;p&gt;Try not to get lost in the code about how to build my person class. The good stuff is at the end with the dyanmic LINQ! Here is my basic "Person" class that will hold our data:&lt;/p&gt;

&lt;div class="CodeBlock C#"&gt;&lt;span class="KeyWord"&gt;public&lt;/span&gt; &lt;span class="KeyWord"&gt;class&lt;/span&gt; Person&lt;br /&gt;
{&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;public&lt;/span&gt; &lt;span class="KeyWord"&gt;string&lt;/span&gt; FirstName { &lt;span class="KeyWord"&gt;get&lt;/span&gt;; &lt;span class="KeyWord"&gt;set&lt;/span&gt;; }&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;public&lt;/span&gt; &lt;span class="KeyWord"&gt;string&lt;/span&gt; LastName { &lt;span class="KeyWord"&gt;get&lt;/span&gt;; &lt;span class="KeyWord"&gt;set&lt;/span&gt;; }&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="KeyWord"&gt;public&lt;/span&gt; DateTime DateOfBirth { &lt;span class="KeyWord"&gt;get&lt;/span&gt;; &lt;span class="KeyWord"&gt;set&lt;/span&gt;; }&lt;br /&gt;
}&lt;/div&gt;

&lt;p&gt;Now I'll create a list with 3 people in there. Then I'll show how to sort it using regular old LINQ. After that, I'll show you how to make your own Expression Tree to dynamically sort it using LINQ (it's exciting)! By the way, it took a lot of reverse engineering and reflecting to figure this out... and in case you're wondering, this is NO WHERE else on the internet right now.&lt;/p&gt;

&lt;div class="CodeBlock C#"&gt;&lt;span class="Comment"&gt;// Here's my list that I am going to sort.&lt;/span&gt;&lt;br /&gt;
List&amp;lt;Person&amp;gt; people = &lt;span class="KeyWord"&gt;new&lt;/span&gt; List&amp;lt;Person&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
people.Add(&lt;span class="KeyWord"&gt;new&lt;/span&gt; Person { FirstName = &lt;span class="String"&gt;"Moses"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;LastName = &lt;span class="String"&gt;"McRoses"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;DateOfBirth = &lt;span class="KeyWord"&gt;new&lt;/span&gt; DateTime(1801, 1, 23) });&lt;br /&gt;
&lt;br /&gt;
people.Add(&lt;span class="KeyWord"&gt;new&lt;/span&gt; Person { FirstName = &lt;span class="String"&gt;"Timothy"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;LastName = &lt;span class="String"&gt;"Khouri"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;DateOfBirth = &lt;span class="KeyWord"&gt;new&lt;/span&gt; DateTime(1985, 6, 20) });&lt;br /&gt;
&lt;br /&gt;
people.Add(&lt;span class="KeyWord"&gt;new&lt;/span&gt; Person { FirstName = &lt;span class="String"&gt;"Jonathan"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;LastName = &lt;span class="String"&gt;"Carter"&lt;/span&gt;,&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;DateOfBirth = &lt;span class="KeyWord"&gt;new&lt;/span&gt; DateTime(1984, 6, 12) });&lt;/div&gt;

&lt;p&gt;As you can see, our list has 3 people that are not in any particular order. Now, I'll sort them by age:&lt;/p&gt;

&lt;div class="CodeBlock C#"&gt;&lt;span class="Comment"&gt;// To &lt;span class="KeyWord"&gt;do&lt;/span&gt; &lt;span class="KeyWord"&gt;this&lt;/span&gt;, you have to have &lt;span class="KeyWord"&gt;using&lt;/span&gt; System.Linq and must&lt;/span&gt;&lt;span class="Comment"&gt;&lt;br /&gt;
// reference the System.Core assembly.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Person[] sortedPeople = people.OrderBy(person =&amp;gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;person.DateOfBirth).ToArray();&lt;/div&gt;

&lt;p&gt;That was simple enough. But what if you bound your "people" list to a GridView that had sorting turned on. The problem here is that you are going to get a STRING that is the NAME of the field that the user wants to sort by. So what do we do?&lt;/p&gt;

&lt;div class="CodeBlock C#"&gt;&lt;span class="Comment"&gt;// This won't work!&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Person[] sortedPeople = people.OrderBy(person =&amp;gt;&lt;br /&gt;
 &amp;nbsp; &amp;nbsp;&lt;span class="String"&gt;"DateOfBirth"&lt;/span&gt;).ToArray();&lt;/div&gt;

&lt;p&gt;The reason why the above won't work is because you're trying to sort by a literal string "DateOfBirth". Since "DateOfBirth" and "DateOfBirth" and "DateOfBirth" are all the same words, then LINQ will ignore this OrderBy alltogether. To achieve what we want, you have to create your own expression tree.&lt;/p&gt;

&lt;div class="CodeBlock C#"&gt;&lt;span class="Comment"&gt;// First we define the parameter that we are going to use&lt;/span&gt;&lt;span class="Comment"&gt;&lt;br /&gt;
// &lt;span class="KeyWord"&gt;in&lt;/span&gt; our OrderBy clause. This &lt;span class="KeyWord"&gt;is&lt;/span&gt; the same &lt;span class="KeyWord"&gt;as&lt;/span&gt; &lt;span class="String"&gt;"(person =&amp;gt;"&lt;/span&gt;&lt;/span&gt;&lt;span class="Comment"&gt;&lt;br /&gt;
// &lt;span class="KeyWord"&gt;in&lt;/span&gt; the example above.&lt;/span&gt;&lt;br /&gt;
&lt;span class="KeyWord"&gt;var&lt;/span&gt; param = Expression.Parameter(&lt;span class="KeyWord"&gt;typeof&lt;/span&gt;(Person), &lt;span class="String"&gt;"person"&lt;/span&gt;);&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
// Now we'll make our lambda function that returns the&lt;/span&gt;&lt;span class="Comment"&gt;&lt;br /&gt;
// &lt;span class="String"&gt;"DateOfBirth"&lt;/span&gt; property by it's name.&lt;/span&gt;&lt;br /&gt;
&lt;span class="KeyWord"&gt;var&lt;/span&gt; mySortExpression = Expression.Lambda&amp;lt;Func&amp;lt;Person, &lt;span class="KeyWord"&gt;object&lt;/span&gt;&amp;gt;&amp;gt;(Expression.Property(param, &lt;span class="String"&gt;"DateOfBirth"&lt;/span&gt;), param);&lt;span class="Comment"&gt;&lt;br /&gt;
&lt;br /&gt;
// Now I can sort my people list.&lt;/span&gt;&lt;br /&gt;
Person[] sortedPeople = people.OrderBy(mySortExpression).ToArray();&lt;/div&gt;

&lt;h3&gt;Dynamic Expression Explaination
&lt;/h3&gt;&lt;p&gt;The code sample above does exactly what the original lambda expression was doing. The reason why I chose to do "Person, object" for my types instead of "Person, DateTime" is because if this was truely dynamic, I wouldn't know the data type of the column being sorted.&lt;/p&gt;

&lt;p&gt;Actually, I should mention that I also wouldn't know the "Person" datatype, so I'd have to use "object, object"... but I'm not going to get into that right now as you'd have to do a pretty hefty chunk of reflection to get the right parameters.&lt;/p&gt;

&lt;p&gt;The more I look into LINQ and expression trees, the more I like it. This stuff may look daunting at first, but when you "get it", you'll really see and appreciate the power it brings.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/295484939" height="1" width="1"/&gt;</description>
			<pubDate>Wed, 26 Mar 2008 07:34:31 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/03/26/Dynamic_LINQ_OrderBy_using_String_Names.aspx</feedburner:origLink></item>
		<item>
			<guid isPermaLink="false">http://www.singingeels.com/Blogs/Nullable/2008/03/24/SingingEels_Update_DONE__I_Cant_Believe_It.aspx</guid>
			<link>http://feeds.feedburner.com/~r/SingingEelsBlogs/~3/295484940/SingingEels_Update_DONE__I_Cant_Believe_It.aspx</link>
			<author>Timothy Khouri</author>
			<title>SingingEels Update DONE! - I Can't Believe It</title>
			<description>&lt;p&gt;After battling with the database for the past hour, I'm finally done uploading all of the previous content (as well as the new code files) to the public SingingEels server! We've re-shaped the site to be a better community experience for everyone, and hopefully it will prove to do so.&lt;/p&gt;

&lt;h3&gt;What Has Been Removed
&lt;/h3&gt;&lt;p&gt;If you'll notice, we no longer have the "Top Authors" section on the right, nor do we have the "Poll of the Day". The reasons for both of these changes is that the "Top Authors" didn't bring any content to the page, and the "Poll of the Day" was more like the poll of the year... that thing got hard to maintain.&lt;/p&gt;

&lt;p&gt;We also removed the "comments RSS" link on the left under the Syndication section. We're going to be adding RSS for comments on an article and blog post basis. This way you can be intuned with a particular subject, rather than just recieving everyone's comments about everything.&lt;/p&gt;

&lt;h3&gt;What We've Added
&lt;/h3&gt;&lt;p&gt;This is the exciting part. First of all, we've added a few more categories: LINQ, Silverlight and WCF for starters. We will likely be changing some of the old categories, and we'll probably also add more. Also, along with the "more categories" is a switch that we made to the category system alltogether. Instead of being "one to one", you can now specify multiple categories for an article.&lt;/p&gt;

&lt;p&gt;Also, blog posts are able to be categorized in the same categories as articles can be. The purpose of this is to provide "related" blog posts next to the article that users are reading. This will help to keep old articles up to date by providing the most recent posts on the topic that users are reading about.&lt;/p&gt;

&lt;h3&gt;Community Experts
&lt;/h3&gt;&lt;p&gt;We have also added a "People to Follow" section (that appears when you're reading an article or blog post). This is a new feature that we are looking to explore to recommend proven community leaders in the topics that you're reading about.&lt;/p&gt;

&lt;p&gt;This list will be kept clean to ensure that we don't recommend random bloggers who consider themselves "the server side guy" or whatever other rediculous self made titles they aquire.&lt;/p&gt;

&lt;h3&gt;Look and Feel
&lt;/h3&gt;&lt;p&gt;We've changed the look and feel a bit. We moved the "recent blogs" section to the right of the main content as we realize that articles (scrutinized content) was being put at a lesser importance. There have been a few other design changes, but not much.&lt;/p&gt;

&lt;h3&gt;Misc and Closing
&lt;/h3&gt;&lt;p&gt;As a side note, we've rewritten the entire site in .NET 3.5 using LINQ (LINQ to SQL in particular). This doesn't mean anything to you (the end user), but it was fun.&lt;/p&gt;

&lt;p&gt;If you have any comments, please feel free to... comment on this blog post! Or you could always drop us a line through the Suggestions Box (link in the left nav). I'm going to focus back on quality articles now.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SingingEelsBlogs/~4/295484940" height="1" width="1"/&gt;</description>
			<pubDate>Mon, 24 Mar 2008 17:56:44 -0600</pubDate>
		<feedburner:origLink>http://www.singingeels.com/Blogs/Nullable/2008/03/24/SingingEels_Update_DONE__I_Cant_Believe_It.aspx</feedburner:origLink></item>
	</channel>
</rss>
