<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
   <channel>
       <title>Thinq LINQ</title>
       <link>/</link>
       <description>Thoughts about LINQ served up with LINQ</description>
       <dc:language>en-US</dc:language>
       <generator>LINQ</generator>

                <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/thinqlinq/rss" /><feedburner:info uri="thinqlinq/rss" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>33.99605</geo:lat><geo:long>-84.474649</geo:long><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><image><link>http://www.ThinqLinq.com</link><url>http://www.ThinqLinq.com/Images/Logo.png</url><title>Thinq Linq</title></image><feedburner:emailServiceId>thinqlinq/rss</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
                      <title>New Paper.li for Reactive Extensions</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/A-ojn4sHRyc/New-Paper.li-for-Reactive-Extensions</link>
                      <pubDate>Fri, 05 Apr 2013 14:23:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22197</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/New-Paper.li-for-Reactive-Extensions</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22197</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/New-Paper.li-for-Reactive-Extensions</wfw:comment>
                      <description>&lt;p&gt;Paper.li is a site that makes it easy to aggregate blog posts, twitter streams, Google+, Facebook, etc into a magazine format for easy reading. There are virtual papers on almost any topic you could imagine. While I’ve seen messages that some of my tweets and links have been featured, I didn’t recall seeing any on the Reactive Extensions (until Now).&lt;/p&gt; &lt;p&gt;I took the liberty of creating a Paper.li specifically for tracking Reactive Extensions news and announcements. Feel free to follow it by clicking on the widget below. Currently I have it scheduled to only publish once a week, but could make it more frequent if necessary. Also, if you can think of a filter I should add or post I should feature, let me know and I’ll see what I can do.&lt;/p&gt;&lt;script src="http://widgets.paper.li/javascripts/init.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script&gt;Paperli.PaperWidget.Show({pid: '21d91b7a-f630-471a-9325-6bb0d5e200ce', width: 200, background: '#FB0000'})&lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=A-ojn4sHRyc:ezYn5T1AVa8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=A-ojn4sHRyc:ezYn5T1AVa8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=A-ojn4sHRyc:ezYn5T1AVa8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=A-ojn4sHRyc:ezYn5T1AVa8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=A-ojn4sHRyc:ezYn5T1AVa8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=A-ojn4sHRyc:ezYn5T1AVa8:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=A-ojn4sHRyc:ezYn5T1AVa8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=A-ojn4sHRyc:ezYn5T1AVa8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=A-ojn4sHRyc:ezYn5T1AVa8:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=A-ojn4sHRyc:ezYn5T1AVa8:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/A-ojn4sHRyc" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/24">Rx</category> 
                        <category domain="/Post.aspx/Category/26">RxJs</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/New-Paper.li-for-Reactive-Extensions</feedburner:origLink></item>
                <item>
                      <title>Beware of Async Sub or Void</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/_Ls1tEbbxro/Beware-of-Async-Sub-or-Void</link>
                      <pubDate>Tue, 02 Apr 2013 18:18:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22196</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Beware-of-Async-Sub-or-Void</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22196</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Beware-of-Async-Sub-or-Void</wfw:comment>
                      <description>&lt;p&gt;At my VS Live last week, I gave a survey of Asynchronous programming from .Net 1 through .Net 4.5. As part of the presentation, I showed off this simple example of doing Async starting with a synchronous example. Here’s the beginning example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;p&gt;    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Main()
        DoWorkAsync()
        Debug.WriteLine(&lt;span class="str"&gt;"All Done"&lt;/span&gt;)&lt;/p&gt;&lt;p&gt;        Console.ReadLine()
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; DoWorkAsync()
        PrintIt()
        Debug.WriteLine(&lt;span class="str"&gt;"Done Async"&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; PrintIt()
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; text = &lt;span class="str"&gt;"Hello World"&lt;/span&gt;
        Task.Delay(2000)
        Debug.WriteLine(text)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/p&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/p&gt;
&lt;p&gt;Before continuing on, try to figure out what you would see in the output window. For those impatient, here’s the output:&lt;/p&gt;
&lt;p&gt;Hello World&lt;br&gt;Done Async&lt;br&gt;All Done&lt;/p&gt;
&lt;p&gt;However, if you try this code, you will notice that the output is all produced prior to the expected 2 second delay (from the Task.Delay). Why is the delay ignored, because the TPL schedules the delay operation on a different thread than the main UI one and then lets the rest of the code operate on the main thread. We can force the delay to pause by changing the PrintIt method as follows:&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; PrintIt()
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; text = &lt;span class="str"&gt;"Hello World"&lt;/span&gt;
        Task.Delay(2000)&lt;font style="background-color: #ffff00"&gt;.Wait()&lt;/font&gt;
        Debug.WriteLine(text)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;
&lt;p&gt;Now, we do delay for the 2 seconds as expected, but we loose any asynchronous behavior that we expected. As a result, we should use the new Async/Await keywords to make our PrintIt method async:&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;Public&lt;/span&gt; Async &lt;span class="kwrd"&gt;Sub&lt;/span&gt; PrintIt()
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; text = &lt;span class="str"&gt;"Hello World"&lt;/span&gt;
        Await Task.Delay(2000)
        Debug.WriteLine(text)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;
&lt;p&gt;Now, if we check our output, we’ll see the following results:&lt;/p&gt;
&lt;p&gt;Done Async&lt;br&gt;All Done&lt;br&gt;(2 second pause)&lt;br&gt;Hello World&lt;/p&gt;
&lt;p&gt;Notice here that the Done Async and All Done messages appear before Hello World.&amp;nbsp; Why? Because when the line with the Await is encountered, control is passed back to the calling method (DoWorkAsync) and schedules the continuation of the await operation on the thread context of the Task.Delay operation. This is just one of the problems with the “Async Sub” or in C#, “async void” patterns. They are acceptable for fire and forget operations, but can cause issues if you want to rely on structured exception handling, resource disposal, and a number of other useful constructs, you shouldn’t use Async Sub. For more information, see &lt;a href="http://blogs.msdn.com/b/lucian/archive/2013/02/18/talk-the-new-async-design-patterns.aspx"&gt;Lucian Wischik’s Async Patterns&lt;/a&gt; article or any of a number of excellent articles by &lt;a href="http://blogs.msdn.com/b/pfxteam/"&gt;Stephen Toub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;So, how do we call the PrintIt operation asynchronously and ensure that it completes prior to continuing the “Done Async”&amp;nbsp; operation? We need to change the signature of the PrintIt method to return a Task rather than returning nothing (void). We then need to move the await up the stack to also Await PrintIt and mark DoWorkAsync as Asynchronous.&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Main()
        DoWorkAsync()
        Debug.WriteLine(&lt;span class="str"&gt;"All Done"&lt;/span&gt;)
        Console.ReadLine()
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;font style="background-color: #ffff00"&gt;Async&lt;/font&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; DoWorkAsync()
        &lt;font style="background-color: #ffff00"&gt;Await &lt;/font&gt;PrintIt()
        Debug.WriteLine(&lt;span class="str"&gt;"Done Async"&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; Async &lt;font style="background-color: #ffff00"&gt;&lt;span class="kwrd"&gt;Function&lt;/span&gt; &lt;/font&gt;PrintIt() &lt;font style="background-color: #ffff00"&gt;&lt;span class="kwrd"&gt;As&lt;/span&gt; Task&lt;/font&gt;
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; text = &lt;span class="str"&gt;"Hello World"&lt;/span&gt;
        Await Task.Delay(2000)
        Debug.WriteLine(text)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Now when we run our program, we see the following output:&lt;/p&gt;
&lt;p&gt;All Done&lt;br&gt;Hello World&lt;br&gt;Done Async&lt;/p&gt;
&lt;p&gt;Notice here that the “All Done” message appears before the 2 second delay, but Hello World and Done Async come out in the expected order showing how the DoWorkAsync operation was indeed run asynchronously from the rest of the app. If you want to see the internals of how the compiler interprets the Async and Await keywords, see my earlier post on using &lt;a href="http://www.thinqlinq.com/Post.aspx/Title/Async-Await-StateMachine-in-ILSpy"&gt;ILSpy with Async&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Also, if you are interested in using Async with Asp.Net or WCF, make sure to check out the &lt;a href="http://channel9.msdn.com/Events/aspConf/aspConf/Async-in-ASP-NET"&gt;Async session from Asp.Net Conf 2012&lt;/a&gt; which details some of the potential issues you should consider there.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_Ls1tEbbxro:aUHAzlySB4c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_Ls1tEbbxro:aUHAzlySB4c:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_Ls1tEbbxro:aUHAzlySB4c:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=_Ls1tEbbxro:aUHAzlySB4c:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_Ls1tEbbxro:aUHAzlySB4c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_Ls1tEbbxro:aUHAzlySB4c:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_Ls1tEbbxro:aUHAzlySB4c:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=_Ls1tEbbxro:aUHAzlySB4c:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_Ls1tEbbxro:aUHAzlySB4c:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=_Ls1tEbbxro:aUHAzlySB4c:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/_Ls1tEbbxro" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 
                        <category domain="/Post.aspx/Category/7">VB</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Beware-of-Async-Sub-or-Void</feedburner:origLink></item>
                <item>
                      <title>CSS Disambiguation with WinJS and SPA</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/RzFT2fc-Roc/CSS-Disambiguation-with-WinJS-and-SPA</link>
                      <pubDate>Thu, 21 Mar 2013 22:00:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22195</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/CSS-Disambiguation-with-WinJS-and-SPA</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22195</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/CSS-Disambiguation-with-WinJS-and-SPA</wfw:comment>
                      <description>&lt;p&gt;Recently, I’ve been working to build with some HTML/JS applications for Windows 8. While I could have built them using XAML/VB-C#, I decided to push myself out of my comfort zone to see what I could do with my web experience in these new Windows Store Apps. In addition, I have a number of customers who are looking to minimize code re-writing by leveraging their existing web assets for these native applications, so I figured I might as well dig into them a bit.&lt;/p&gt; &lt;p&gt;I’m used to the standard page per request model and AJAX based models, but the Windows-8 implementation follows more along the lines of the Single Page Application (SPA) model. As a result, some things become easier (like state management across pages) while others become more tricky (make sure to avoid the global namespace as more JavaScript will stay alive in your apps now).&lt;/p&gt; &lt;p&gt;One of the first Issues I came up against was an issue when navigating between pages and finding that styles that are being applied in child pages are sticking when navigating back to the parent page. I’m sure I’m not alone as &lt;a href="http://stackoverflow.com/questions/11997190/winjs-not-unloading-js-css"&gt;this Stack Overflow post&lt;/a&gt; indicates.This wouldn’t be an issue in a standard web implementation because the page would be re-loaded along with only the styles that page requested. However, in the Windows Store App model, each page that is loaded will bring it’s associated css and js into scope &lt;strong&gt;the first time the page is loaded and be retained&lt;/strong&gt; as we navigate to other pages. Let’s take a look at an example app to see how this works.&lt;/p&gt; &lt;p&gt;Let’s start by creating a new JavaScript app using the Navigation App template. This will create a solution framework with a default.html page that loads a home.html page into a div called “contenthost”&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_thumb.png" width="433" height="167"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;To keep this sample as simple as possible, I’m just going to add one more page to the default template. To do this, create a new folder in the pages folder in the Solution Explorer. I’ll call this folder Detail. In the Detail folder, add a new Page using the Page Control template and call it DetailPage.html.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_3.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_thumb_3.png" width="437" height="199"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The Page Control template will generate three files in our folder – DetailPage.html, DetailPage.js and DetailPage.css. This allows us to follow a good coding pattern to keep our concerns separated between layout semantics (html), logic (js), and presentation (css). We’re not going to modify the html of this page, instead we’ll just tweak the css to apply a bit of styling to our h1 tag to set the font to Comic Sans MS. Note, I don’t recommend making this particular change in your apps. This change is just for demonstration purposes! Open the DetailPage.css and add the following to it:&lt;/p&gt;&lt;pre class="csharpcode"&gt;h1{
    font-family:'Comic Sans MS', cursive;
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;With that change, we now need to give the user the ability to navigate from the home page to our new page. In the home.html page, let’s add the highlighted line giving the user an anchor tag to click:&lt;/p&gt;&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;section&lt;/span&gt; &lt;span class="attr"&gt;aria-label&lt;/span&gt;&lt;span class="kwrd"&gt;="Main content"&lt;/span&gt; &lt;span class="attr"&gt;role&lt;/span&gt;&lt;span class="kwrd"&gt;="main"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;p&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Content goes here.&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;p&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;font style="background-color: #ffff00"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="detailButton"&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="#"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;View Detail&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;section&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Finally, let’s add a click handler for the “button” in the home.js file:&lt;/p&gt;&lt;pre class="csharpcode"&gt;  ready: &lt;span class="kwrd"&gt;function&lt;/span&gt; (element, options) {
      element.querySelector(&lt;span class="str"&gt;"#detailButton"&lt;/span&gt;).addEventListener(&lt;span class="str"&gt;'click'&lt;/span&gt;,
           &lt;span class="kwrd"&gt;function&lt;/span&gt; () { WinJS.Navigation.navigate(&lt;span class="str"&gt;'/pages/Detail/DetailPage.html'&lt;/span&gt;) });
  }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Now that we're done, we can navigate to our page to view our handy work. Hit F5 to run the app to see your impressive L337 skillz.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_4.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_thumb_4.png" width="339" height="131"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next, navigate to the detail screen by clicking your link.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_5.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_thumb_5.png" width="345" height="98"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Notice here, because we used the WinJS.Navigation.navigate method to move to this page rather than just setting the href on the anchor tag, we magically have the default back button to get back to the home page. Try clicking it now.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_6.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_thumb_6.png" width="348" height="127"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Compare the first screen shot with this one. Do you notice anything unusual? The page title is now the wrong font. If we look at the Solution Explorer while debugging, the situation starts to make sense. Notice here that the DetailPage.js is still loaded even though we have navigated back to the home page. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_7.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://www.thinqlinq.com/images/a9854c41a0f2_EC48/image_thumb_7.png" width="218" height="344"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As I stated earlier, in WinJS applications, the js and css files are loaded when they are first used and retained in memory rather than being refetched for each page request as is done in web pages. Since the styles are applied in the order that they are fetched, the last version of the font that applied to the h1 is the one that came from DetailPage.css. We can’t just try to set the style explicitly again in the home.css, because it was already previously loaded, so it won’t be re-loaded again.&lt;/p&gt;
&lt;p&gt;In this case, if we want to globally modify the style, we should make then change in the default.css located in the css folder of our project. If we want to modify the style only for the lifetime of our individual detail page, we need to preface the style with a page class that is specific to our page. Looking at our DetailPage.html, we can see that the page template wizard generated the necessary class for us already.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="DetailPage fragment"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;header&lt;/span&gt; &lt;span class="attr"&gt;aria-label&lt;/span&gt;&lt;span class="kwrd"&gt;="Header content"&lt;/span&gt; &lt;span class="attr"&gt;role&lt;/span&gt;&lt;span class="kwrd"&gt;="banner"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;button&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="win-backbutton"&lt;/span&gt; &lt;span class="attr"&gt;aria-label&lt;/span&gt;&lt;span class="kwrd"&gt;="Back"&lt;/span&gt; &lt;span class="attr"&gt;disabled&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;button&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;h1&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="titlearea win-type-ellipsis"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;span&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="pagetitle"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Welcome to DetailPage&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;span&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;h1&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;header&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;section&lt;/span&gt; &lt;span class="attr"&gt;aria-label&lt;/span&gt;&lt;span class="kwrd"&gt;="Main content"&lt;/span&gt; &lt;span class="attr"&gt;role&lt;/span&gt;&lt;span class="kwrd"&gt;="main"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;p&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Content goes here.&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;p&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;section&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Notice that the main div uses the “DetailPage fragment” class. With this we can preface the h1 style in the DetailPage.css file with the .DetailPage class selector to indicate that the style should only be applied to this page:&lt;/p&gt;&lt;pre&gt;.DetailPage h1 {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; font-family:'Comic Sans MS', cursive;
}&lt;/pre&gt;
&lt;p&gt;If we run the application again, we should see that when we navigate back to the home page, the font is (thankfully) no longer Comic Sans MS, but has reverted to the oh so much more wonderful Windows 8 default of Segoe UI. If you don’t’ believe me and want to try this out for yourself, feel free to type the code in above, or just &lt;a href="http://www.thinqlinq.com/downloads/CssDisambiguate.zip"&gt;download the project&lt;/a&gt; and try it yourself. I know, I could have told you about the download link in the beginning, but where’s the fun in that? &lt;/p&gt;
&lt;p&gt;Have you run into this issue and found alternative solutions, I’d love to know what you thinq.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=RzFT2fc-Roc:pLEgZo1UE1I:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=RzFT2fc-Roc:pLEgZo1UE1I:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=RzFT2fc-Roc:pLEgZo1UE1I:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=RzFT2fc-Roc:pLEgZo1UE1I:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=RzFT2fc-Roc:pLEgZo1UE1I:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=RzFT2fc-Roc:pLEgZo1UE1I:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=RzFT2fc-Roc:pLEgZo1UE1I:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=RzFT2fc-Roc:pLEgZo1UE1I:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=RzFT2fc-Roc:pLEgZo1UE1I:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=RzFT2fc-Roc:pLEgZo1UE1I:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/RzFT2fc-Roc" height="1" width="1"/&gt;</description>

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/CSS-Disambiguation-with-WinJS-and-SPA</feedburner:origLink></item>
                <item>
                      <title>Blog evolution</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/E-Y6lZuLCtg/Blog-evolution</link>
                      <pubDate>Thu, 21 Mar 2013 19:03:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22194</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Blog-evolution</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22194</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Blog-evolution</wfw:comment>
                      <description>&lt;p&gt;Five years ago, I started this blog as a site written in LINQ dedicated to talking about LINQ. In the years that have followed, I’ve expanded the discussions to include a number of LINQ and language design related topics, including Entity Framework, Reactive Extensions, and other items. Over-all, I’ve tried to limit the scope of the topics to LINQ related issues. &lt;/p&gt; &lt;p&gt;Although I still love LINQ and thinq it is a great technology, I’ve been increasingly working with other technologies and as a result, I have shied away from posting about them here for the fear of alienating my LINQ loving fans. Now that LINQ has been around for over half a decade, I suppose it is time to allow the topics on this site evolve as well and start discussing some of the newer things that I’m encountering in the various technologies that I’m working with to spread the love (or love-hate as the case is from time to time) of that technology with the rest of you. &lt;/p&gt; &lt;p&gt;My hope is that you can continue to grow with me and continue to find value in the posts that will come. Of course, I’ll continue to post about LINQ related items as I find the inspiration and time. If you find yourself turned off by the non-LINQ related posts, let me know and I can consider moving the blog off onto another domain. I'm always open to knowing what you thinq.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=E-Y6lZuLCtg:Rnilmg5UT7I:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=E-Y6lZuLCtg:Rnilmg5UT7I:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=E-Y6lZuLCtg:Rnilmg5UT7I:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=E-Y6lZuLCtg:Rnilmg5UT7I:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=E-Y6lZuLCtg:Rnilmg5UT7I:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=E-Y6lZuLCtg:Rnilmg5UT7I:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=E-Y6lZuLCtg:Rnilmg5UT7I:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=E-Y6lZuLCtg:Rnilmg5UT7I:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=E-Y6lZuLCtg:Rnilmg5UT7I:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=E-Y6lZuLCtg:Rnilmg5UT7I:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/E-Y6lZuLCtg" height="1" width="1"/&gt;</description>

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Blog-evolution</feedburner:origLink></item>
                <item>
                      <title>Unit testing rules of thumb</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/pXlFNVzqAuE/Unit-testing-rules-of-thumb</link>
                      <pubDate>Thu, 07 Mar 2013 16:16:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22193</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Unit-testing-rules-of-thumb</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22193</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Unit-testing-rules-of-thumb</wfw:comment>
                      <description>&lt;p&gt;Earlier this week, &lt;a href="https://twitter.com/unclebobmartin"&gt;Uncle Bob&lt;/a&gt; stirred up the TDD hornet nest again trying to wade the fine line between RAD and pure TDD with excessive use of IOC’s. In one of the many responses to the twitter debate, &lt;a href="http://lostechies.com/jimmybogard/2013/03/06/when-should-you-test/"&gt;Jimmy Bogard responded&lt;/a&gt; that you should use testing methodologies, “When it provides value … it depends.”&amp;nbsp; Since I am speaking about Unit Testing in SharePoint at the upcoming VS Live events, I figured I should put in my two cents as well.&lt;/p&gt; &lt;p align="center"&gt;&lt;a href="http://vslive.com/Events/Las-Vegas-2013/Home.aspx?utm_source=AttendeeMktg&amp;amp;utm_medium=Fax&amp;amp;utm_campaign=VLSPK33"&gt;&lt;img title="VSL13_Badge_See125x125" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="VSL13_Badge_See125x125" src="http://www.thinqlinq.com/images/Unit-testing-rules-of-thumb_8BF6/VSL13_Badge_See125x125.jpg" width="129" height="129"&gt;&lt;/a&gt;&lt;a href="http://vslive.com/events/chicago-2013/home.aspx?utm_source=AttendeeMktg&amp;amp;utm_medium=Fax&amp;amp;utm_campaign=CHSPK28"&gt;&lt;img title="VSLCH13_Badge_See125x125" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="VSLCH13_Badge_See125x125" src="http://www.thinqlinq.com/images/Unit-testing-rules-of-thumb_8BF6/VSLCH13_Badge_See125x125.gif" width="129" height="129"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In general, I tend to agree with Jimmy’s pragmatic approach. I’m not a test first zealot by any means, and don’t think that trying to achieve 100% code coverage is a panacea. Indeed, even if you do have 100% code coverage, there can be significant business rules that you may not be testing that you should have tests for. Also, your code may well have exception checking, input validation, data binding, etc. code that spending time testing can only decrease your overall ROI.&lt;/p&gt; &lt;p&gt;When designing systems, I tend to use the following rules of thumb to guide me in when to write coded tests for my solutions. This list is likely not inclusive and as always, &lt;a href="http://answers.yahoo.com/question/index?qid=20070302225244AAgOTxN"&gt;to every rule there is an exception&lt;/a&gt;.&lt;/p&gt; &lt;h4&gt;If it’s a core piece of business logic, it should have a test.&lt;/h4&gt; &lt;p&gt; When building systems, there will be a number of cases where business rules assert that under certain situations something specific should happen. In those cases, I recommend writing a unit test. The test should be named appropriate to the business defined rule. For example, if the user should be notified when customer’s age a value drops below an acceptable minimum, I would name the test something along the lines of Customer_InvalidWhenAgeBelow18. This way we document the system requirements through the tests and have a quick way of validating our logic directly with the stakeholders to make sure our tests are asserting the correct things. Once we are done, we can give the test report to the customer to show them that all of their assertions are coming up true before handing off the code.&lt;/p&gt; &lt;h4&gt;If you hit F5 to debug an issue more than 5 times, it would have been quicker to write an automated test for it.&lt;/h4&gt; &lt;p&gt;On most systems that I work with, the act of debugging an issue can be quite time consuming. Just navigating the system to the point where you want to test often involves a number of steps, including logging into the system, creating a new record, setting the test values, trying to submit the values and checking the results. Often, if you took the time to write up a testing harness for these situations, you can bypass many of the manual steps and just test the logic that you need in isolation. Additionally, if you take the appropriate time upfront to set some test objects (fakes or mocks), then they can be reused for similar tests in the future – further reducing your future testing development time and effort.&lt;/p&gt; &lt;h4&gt;If there’s a complex calculation that you are automating, include tests for it.&lt;/h4&gt; &lt;p&gt;Even the most thorough coder can make simple math errors when coding calculations. Flipping a “+/-“ check or evaluating a complex logical truth table can be a brain twisting task at times. A simple error can ripple through the system causing unexpected errors. In many cases when automating calculations, you know up-front what some of the expected input and output values are. Write specific tests for them up-front and you will be well rewarded down the road. Better yet, write one test and provide a list (in Excel/Xml/etc.) with the valid inputs and outputs and then use a &lt;a href="http://msdn.microsoft.com/tr-tr/library/ms182527(v=VS.100).aspx"&gt;data driven test&lt;/a&gt; approach to evaluate the various permutations of the values.&lt;/p&gt; &lt;h4&gt;If there is a user detected bug in logic, write a test before fixing the bug.&lt;/h4&gt; &lt;p&gt;All too often, I find my developers trying to debug an issue and thinking they’ve found the solution only to realize that they just located a different bug and never actually fixed the true defect. When writing tests, you should aim to write them so that they fail first and only pass once you’ve corrected the underlying defect.&amp;nbsp; I’ve also seen tests that appear to have passed even when the test failed, but the author of the test never knew it because the test was always passing (in most cases, they were swallowing test failure exceptions). By writing your test to fail first and then fixing the implementation, you are assured that your fix solves the problem at hand, and have a built-in regression test for future changes. &lt;/p&gt; &lt;p&gt;Often, when trying to get teams to start using a testing approach, I have to work to convince them that the tests are worth the time and effort. Typically, I find resistance particularly from teams that follow the just “get ‘er done” approach. In the consulting world, we often feel the pressure of producing the requested system at the expense of tests which are typically not included as a payable deliverable. However by building up a testing suite, we typically find the value when a test locates a regression defect prior to shipping the product which would have had a cost if it shipped with the defect. Following this more pragmatic approach and remembering these rules of thumb can provide a sense of safety in refactoring and increase your agility and velocity over time when maintaining systems.&lt;/p&gt; &lt;p&gt;Do you have additional rules of thumb that help to guide you? Let me know what you Thinq.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=pXlFNVzqAuE:RwBIqACyz9Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=pXlFNVzqAuE:RwBIqACyz9Q:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=pXlFNVzqAuE:RwBIqACyz9Q:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=pXlFNVzqAuE:RwBIqACyz9Q:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=pXlFNVzqAuE:RwBIqACyz9Q:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=pXlFNVzqAuE:RwBIqACyz9Q:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=pXlFNVzqAuE:RwBIqACyz9Q:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=pXlFNVzqAuE:RwBIqACyz9Q:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=pXlFNVzqAuE:RwBIqACyz9Q:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=pXlFNVzqAuE:RwBIqACyz9Q:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/pXlFNVzqAuE" height="1" width="1"/&gt;</description>

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Unit-testing-rules-of-thumb</feedburner:origLink></item>
                <item>
                      <title>External USB Monitor for road warriors</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/f9Sj0X8U6WM/External-USB-Monitor-for-road-warriors</link>
                      <pubDate>Mon, 04 Mar 2013 14:12:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22192</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/External-USB-Monitor-for-road-warriors</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22192</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/External-USB-Monitor-for-road-warriors</wfw:comment>
                      <description>&lt;p&gt;I’ve been a consultant for a number of years. Typically, I’m working on a customer’s site to provide solutions for them both in what I’m currently working on, and to pay attention to other needs that they may have that I can help to offer solutions for. At the client’s location I’m given a desk to work at, but I’m responsible for my own equipment. The laptop situation is no problem, but I’ve been spoiled by having dual monitors in the past. &lt;/p&gt;&lt;iframe style="height: 240px; float: right; width: 120px" marginheight="0" src="http://rcm.amazon.com/e/cm?lt1=_blank&amp;amp;bc1=000000&amp;amp;IS2=1&amp;amp;bg1=FFFFFF&amp;amp;fc1=000000&amp;amp;lc1=0000FF&amp;amp;t=woolswond-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as4&amp;amp;m=amazon&amp;amp;f=ifr&amp;amp;ref=ss_til&amp;amp;asins=B005SEZR0G" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt; &lt;p&gt;Six months ago, I happened upon a great solution to the problem. The &lt;a href="http://www.amazon.com/dp/B005SEZR0G/ref=as_li_ss_til?tag=woolswond-20&amp;amp;camp=213381&amp;amp;creative=390973&amp;amp;linkCode=as4&amp;amp;creativeASIN=B005SEZR0G&amp;amp;adid=05SE77X2PG13PE52SYZD&amp;amp;&amp;amp;ref-refURL=http%3A%2F%2Fwww.thinqlinq.com%2F"&gt;AOC 16” USB powered monitor&lt;/a&gt;. It is just about the same size as my laptop and offers an additional 16” display at 1366x798 resolution. This is great for email, twitter, and debugging purposes. Being a USB monitor I can’t recommend using it for hi-res video, but then again, you wouldn’t be watching Netflix on the job anyway, right?&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=f9Sj0X8U6WM:Kht9nQvN7AE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=f9Sj0X8U6WM:Kht9nQvN7AE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=f9Sj0X8U6WM:Kht9nQvN7AE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=f9Sj0X8U6WM:Kht9nQvN7AE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=f9Sj0X8U6WM:Kht9nQvN7AE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=f9Sj0X8U6WM:Kht9nQvN7AE:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=f9Sj0X8U6WM:Kht9nQvN7AE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=f9Sj0X8U6WM:Kht9nQvN7AE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=f9Sj0X8U6WM:Kht9nQvN7AE:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=f9Sj0X8U6WM:Kht9nQvN7AE:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/f9Sj0X8U6WM" height="1" width="1"/&gt;</description>

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/External-USB-Monitor-for-road-warriors</feedburner:origLink></item>
                <item>
                      <title>JSON Literals for VB</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/6Sj6oQbLVQQ/JSON-Literals-for-VB</link>
                      <pubDate>Fri, 01 Mar 2013 20:53:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22191</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/JSON-Literals-for-VB</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22191</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/JSON-Literals-for-VB</wfw:comment>
                      <description>&lt;p&gt;One of the stand-out features of VB.Net since VB9 has been the inclusion of XML Literals. Followers of this blog should be well familiar with the concept because I &lt;a href="http://www.thinqlinq.com/Post.aspx/Title/LINQ-to-XML-Rocks-Because"&gt;first wrote about XML Literals&lt;/a&gt; way back in 2006. With them, we can imbed XML directly into our code as follows:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; value = &amp;lt;root&amp;gt;
                &amp;lt;child attrib=&lt;span class="str"&gt;"foo"&lt;/span&gt;&amp;gt;bar&amp;lt;/child&amp;gt;
            &amp;lt;root&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;While XML Literals make the task of working with XML more of a joy than a necessary evil, they do add a certain level of complexity to the language. Any language feature then needs to be maintained moving forward. When I asked Anders about adding them to C#, he pointed to the ongoing maintenance issue along with the supposition that although XML was becoming a de-facto data persistence syntax, would adopting the literals into the language then set a precedence that they would need to support other persistence mechanisms when XML was replaced with some other syntax. &lt;/p&gt;
&lt;p&gt;With the rise of REST and decline of SOAP, we have indeed seen the popularity of XML wane in favor of the more compact json syntax. The popularity is increased due to the fact that most JavaScript clients make parsing json into objects trivial. As a result, I have had conversations at conferences joking about the need for json literals in the language as well. At a recent conference an idea came to me which could actually make them (almost) a reality. &lt;/p&gt;
&lt;p&gt;At its heart, json is simply a string representation of the JavaScript object structures. These object structures behave much like the .Net dynamic PropertyBag object. As a result, all we really need is a way to embed a long, multi-line string into our VB code and then parse it into a dynamic PropertyBag in order to consume it. Unfortunately, VB doesn’t support multi-line strings. However, it does support multi-line XML. All we need to do is wrap the multi line string inside of an XML element literal:&lt;/p&gt;&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; jsonLiteral = &amp;lt;js&amp;gt;[
            {author:&lt;span class="rem"&gt;'Jim Wooley', bookName:'LINQ in Action'},&lt;/span&gt;
            {author:&lt;span class="rem"&gt;'Frank Herbert', bookName:'Dune'},&lt;/span&gt;
            {author:&lt;span class="rem"&gt;'Joe Albahari', bookName:'LINQ Pocket Reference'},&lt;/span&gt;
            {author:&lt;span class="rem"&gt;'Joseph Rattz', bookName:'Pro LINQ'},&lt;/span&gt;
            {author:&lt;span class="rem"&gt;'Charlie Calvert', bookName:'Essential LINQ'}&lt;/span&gt;
        ]&amp;lt;/js&amp;gt;&lt;/pre&gt;
&lt;p&gt;With that, we just need to decode the jsonLiteral.Value into a dynamic object. A quick search of &lt;a href="http://stackoverflow.com/questions/3142495/deserialize-json-into-c-sharp-dynamic-object"&gt;Stack Overflow&lt;/a&gt; finds a number of handy options for this task. For the sake of this example, I’m just going to use the System.Web.Helpers.Json library that’s part of MVC. We’ll create an extension method to take an XElement and convert it into a dynamic object using the Json.Decode method:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&amp;lt;Extension&amp;gt;
&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Module&lt;/span&gt; JsonExtensions
    &amp;lt;Extension&amp;gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; JsonDecode(input &lt;span class="kwrd"&gt;As&lt;/span&gt; XElement) &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt;
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; Json.Decode(input.Value)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Module&lt;/pre&gt;
&lt;p&gt;With this in place, we can now operate on the literal just as if it was any other dynamic object type. Here’s the full code for this example.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Option&lt;/span&gt; Strict Off

&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Runtime.CompilerServices
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Web.Helpers

&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; Test1

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; TestJsonLiteral()
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; jsonLiteral = &amp;lt;js&amp;gt;[
            {author:&lt;span class="rem"&gt;'Jim Wooley', bookName:'LINQ in Action'},&lt;/span&gt;
            {author:&lt;span class="rem"&gt;'Frank Herbert', bookName:'Dune'},&lt;/span&gt;
            {author:&lt;span class="rem"&gt;'Joe Albahari', bookName:'LINQ Pocket Reference'},&lt;/span&gt;
            {author:&lt;span class="rem"&gt;'Joseph Rattz', bookName:'Pro LINQ'},&lt;/span&gt;
            {author:&lt;span class="rem"&gt;'Charlie Calvert', bookName:'Essential LINQ'}&lt;/span&gt;
        ]&amp;lt;/js&amp;gt;

        &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; book &lt;span class="kwrd"&gt;In&lt;/span&gt; jsonLiteral.JsonDecode()
            Console.WriteLine(book.author)
        &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt;

&amp;lt;Extension&amp;gt;
&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Module&lt;/span&gt; JsonExtensions
    &amp;lt;Extension&amp;gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; JsonDecode(input &lt;span class="kwrd"&gt;As&lt;/span&gt; XElement) &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt;
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; Json.Decode(input.Value)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Module&lt;/pre&gt;
&lt;p&gt;I’m sure that there are features that this technique doesn’t cover (including LINQ because Object isn’t directly convertible to IEnumerable). I’m also not sure if this really has any practical benefit. It just is interesting to consider.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=6Sj6oQbLVQQ:UIPAnjvlZJY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=6Sj6oQbLVQQ:UIPAnjvlZJY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=6Sj6oQbLVQQ:UIPAnjvlZJY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=6Sj6oQbLVQQ:UIPAnjvlZJY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=6Sj6oQbLVQQ:UIPAnjvlZJY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=6Sj6oQbLVQQ:UIPAnjvlZJY:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=6Sj6oQbLVQQ:UIPAnjvlZJY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=6Sj6oQbLVQQ:UIPAnjvlZJY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=6Sj6oQbLVQQ:UIPAnjvlZJY:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=6Sj6oQbLVQQ:UIPAnjvlZJY:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/6Sj6oQbLVQQ" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/7">VB</category> 
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 
                        <category domain="/Post.aspx/Category/18">Linq to XML</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/JSON-Literals-for-VB</feedburner:origLink></item>
                <item>
                      <title>INETA Community Champion for 2012 Q4</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/1k6KlcK0NNg/INETA-Community-Champion-for-2012-Q4</link>
                      <pubDate>Mon, 04 Feb 2013 20:58:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22190</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/INETA-Community-Champion-for-2012-Q4</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22190</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/INETA-Community-Champion-for-2012-Q4</wfw:comment>
                      <description>&lt;p&gt;&lt;a href="http://inetachamps.com/Profile/Details/Jim"&gt;&lt;img border="0" alt="INETA Community Champions" align="right" src="http://inetachamps.com/Profile/GetBadge/Jim"&gt;&lt;/a&gt; I’ve been active in the technology community since 2000 when .Net was just announced. This started with doing some small talks at user group meetings and helping to update their web site. It didn’t take long before I was running meetings and networking with other groups. &lt;/p&gt; &lt;p&gt;Over the years, I’ve gradually increased my reach by speaking at events increasingly far from my home base, including events as far away as London, Las Vegas, and Redmond. Prior to it’s being disbanded, my speaking involvement lead me to being selected as a member of the INETA Speaker Bureau. I continue to work with INETA as a member of their more localized version, the &lt;a href="http://www.ineta.org/Speakers/Default.aspx"&gt;INETA Community Speakers&lt;/a&gt; program.&lt;/p&gt; &lt;p&gt;I’ve also continued reaching out to help mentor other user group leaders through being an INETA Membership Mentor for a number of years. I also participate in UG Leader summits when I’m able.&lt;/p&gt; &lt;p&gt;Recently, I was honored to be recognized by my peers as an &lt;a href="http://inetachamps.com/Profile/Details/Jim"&gt;INETA Community Champion&lt;/a&gt; for Q4 2012. While I never aspired for such recognition, it’s a privilege to have my efforts recognized by the community at large. Having received this award doesn’t mean the work is done. I continue to share my experiences with others to help grow the community as much as I can. Who knows what the future might bring, but I hope I can continue to bring the love of technology to others, just as my mentors have done for me in the past.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=1k6KlcK0NNg:IWDOXp-JCj0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=1k6KlcK0NNg:IWDOXp-JCj0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=1k6KlcK0NNg:IWDOXp-JCj0:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=1k6KlcK0NNg:IWDOXp-JCj0:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=1k6KlcK0NNg:IWDOXp-JCj0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=1k6KlcK0NNg:IWDOXp-JCj0:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=1k6KlcK0NNg:IWDOXp-JCj0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=1k6KlcK0NNg:IWDOXp-JCj0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=1k6KlcK0NNg:IWDOXp-JCj0:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=1k6KlcK0NNg:IWDOXp-JCj0:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/1k6KlcK0NNg" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/2">Code Camp</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/INETA-Community-Champion-for-2012-Q4</feedburner:origLink></item>
                <item>
                      <title>Office 2013 RT excludes programming features</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/WwQ1mRNNois/Office-2013-RT-excludes-programming-features</link>
                      <pubDate>Tue, 13 Nov 2012 16:29:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22189</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Office-2013-RT-excludes-programming-features</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22189</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Office-2013-RT-excludes-programming-features</wfw:comment>
                      <description>&lt;p&gt;When I started my programming career, I started with writing Access applications with VBA. While I have moved away from these applications for the most part, I occasionally find the need to come back to office automation tasks in Excel, Word and Access. When reviewing the version of Office that comes with the new Surface tablet running Windows RT and Office 2013 RT, I checked out the developer tool bar to see what it offered. Here’s the new toolbar in Excel 2013 RT:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/1994e4bf71a4_9D53/ExcelDeveloperToolbar.png"&gt;&lt;img title="ExcelDeveloperToolbar" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="ExcelDeveloperToolbar" src="http://www.thinqlinq.com/images/1994e4bf71a4_9D53/ExcelDeveloperToolbar_thumb.png" width="509" height="182"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;As a point of reference, here is the toolbar as it appeared in Excel 2010:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/1994e4bf71a4_9D53/Excel2010DeveloperBar.png"&gt;&lt;img title="Excel2010DeveloperBar" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="Excel2010DeveloperBar" src="http://www.thinqlinq.com/images/1994e4bf71a4_9D53/Excel2010DeveloperBar_thumb.png" width="508" height="82"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Notice here that the Code (including VBA and Macros), Add-ins, and Controls sections have been removed from the RT version of Office. I suspect the issue here is that VBA is really locked into the x86 architecture. Since Windows RT runs on the ARM rather than x86 processors, the amount of effort to migrate this functionality was not worth the effort.&lt;/p&gt; &lt;p&gt;As a result, if you have Office solutions that you want to continue to use on the new platforms, be careful what features you use. If you need to continue building solutions based on office, I suspect that support will be added for the new &lt;a href="http://msdn.microsoft.com/en-us/library/office/apps/jj220082(v=office.15)"&gt;Office app model&lt;/a&gt; based on HTML and JavaScript. While we’ve heard rumblings for some time on the impending demise of VBA, this appears to be a clear sign that continuing to invest time and money on extending the old VBA based solutions appears to be a dead-end solution in the new tablet/mobile world.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WwQ1mRNNois:1rHoinEy1S4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WwQ1mRNNois:1rHoinEy1S4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WwQ1mRNNois:1rHoinEy1S4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=WwQ1mRNNois:1rHoinEy1S4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WwQ1mRNNois:1rHoinEy1S4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WwQ1mRNNois:1rHoinEy1S4:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WwQ1mRNNois:1rHoinEy1S4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=WwQ1mRNNois:1rHoinEy1S4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WwQ1mRNNois:1rHoinEy1S4:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=WwQ1mRNNois:1rHoinEy1S4:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/WwQ1mRNNois" height="1" width="1"/&gt;</description>

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Office-2013-RT-excludes-programming-features</feedburner:origLink></item>
                <item>
                      <title>Hierarchical Trees from Flat Tables using LINQ</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/ovio7JDBOu4/Hierarchical-Trees-from-Flat-Tables-using-LINQ</link>
                      <pubDate>Fri, 05 Oct 2012 20:46:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22188</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Hierarchical-Trees-from-Flat-Tables-using-LINQ</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22188</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Hierarchical-Trees-from-Flat-Tables-using-LINQ</wfw:comment>
                      <description>&lt;p&gt;I’m often tasked with creating a tree representation of a structure from a flat self-referencing table. For example, in the EF extensions to Northwind, they extended the Employee table so that it has a self-referencing “ReportsTo” column. As you can see from the data below, Andrew Fuller does not report to any other employees, but Nancy, Janet, Margaret, Steven, and Laura all report to Andrew (because their ReportsTo value is the same as Andrew’s EmployeeID). Likewise Michael, Robert, and Anne all report to Steven.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.thinqlinq.com/Images/9a41f8e74984_E3CC/image.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.thinqlinq.com/Images/9a41f8e74984_E3CC/image_thumb.png" width="244" height="178"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In order to generate a tree representation of these records, we could start with any records that have no direct reports and then lazy load each of their children. Unfortunately for large graphs, the number of database hits will grow exponentially as we add tree levels. Typically with parent-child relationships, we could eager load the children using the DataLoadOptions with LINQ to SQL or .Includes with Entity Framework. However with self-referencing entities, this isn’t allowed. With LINQ to SQL, you will get an InvalidOperationException “Cycles not allowed in LoadOptions LoadWith type graph.”&lt;/p&gt; &lt;p&gt;So, how do we load the tree in one pass and build the object graphs? It’s really not that hard once you realize how reference types (classes) work in .Net. Let’s start by creating a holder for each employee and their associated direct reports:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; HierarchicalEmployee
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(emp &lt;span class="kwrd"&gt;As&lt;/span&gt; Employee)
           Model = emp
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Model &lt;span class="kwrd"&gt;As&lt;/span&gt; Employee
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; DirectReports &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; List(Of HierarchicalEmployee)
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Now that we have this type, we can fill it using a simple LINQ request. In order to optimize the next step, we’ll push the values into an in-memory Dictionary indexed by the EmployeeID:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; allEmployees = Employees.
    &lt;span class="kwrd"&gt;Select&lt;/span&gt;(&lt;span class="kwrd"&gt;Function&lt;/span&gt;(emp) &lt;span class="kwrd"&gt;New&lt;/span&gt; HierarchicalEmployee(emp)).
    ToDictionary(&lt;span class="kwrd"&gt;Function&lt;/span&gt;(emp) emp.Model.EmployeeID)&lt;/pre&gt;
&lt;p&gt;Next, we iterate over the full list. For records that have a ReportsTo value, we’ll add their object pointer to their parent’s DirectReports list:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; emp &lt;span class="kwrd"&gt;In&lt;/span&gt; allEmployees.Values
  &lt;span class="kwrd"&gt;If&lt;/span&gt; emp.Model.ReportsTo.HasValue &lt;span class="kwrd"&gt;Then&lt;/span&gt;
    allEmployees(emp.Model.ReportsTo.Value).DirectReports.Add(emp)
  &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
Next&lt;/pre&gt;
&lt;p&gt;Notice, here we take advantage of the Dictionary’s hash rather than having to iterate over the list each time we want to find the parent record. Finally, instead of returning the full list, we only return the employees that don’t have any children (where the ReportsTo is null).&lt;/p&gt;&lt;pre class="csharpcode"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; rootEmployees = allEmployees.Values.
    Where(&lt;span class="kwrd"&gt;function&lt;/span&gt;(emp) &lt;span class="kwrd"&gt;Not&lt;/span&gt; emp.Model.ReportsTo.HasValue())&lt;/pre&gt;
&lt;p&gt;If we want to test this out in &lt;a href="http://Linqpad.net"&gt;LinqPad&lt;/a&gt;, just use the Dump method on the resulting rootEmployees. As a result, you’ll see the following in the results pane. Notice Andrew is the only root object. He has 5 direct reports and one of his reports had 3 reports. You could just as easily bind this to a treeview control or output it using your favorite UI tooling.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.thinqlinq.com/Images/9a41f8e74984_E3CC/image_3.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.thinqlinq.com/Images/9a41f8e74984_E3CC/image_thumb_3.png" width="651" height="285"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The nice thing about this solution is that if we check the generated SQL, we will just see a simple (single) SQL request to generate the entire graph. As a summary, here’s the complete code from the LinqPad sample:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Sub&lt;/span&gt; Main
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; allEmployees = Employees.
        &lt;span class="kwrd"&gt;Select&lt;/span&gt;(&lt;span class="kwrd"&gt;Function&lt;/span&gt;(emp) &lt;span class="kwrd"&gt;New&lt;/span&gt; HierarchicalEmployee(emp)).
        ToDictionary(&lt;span class="kwrd"&gt;Function&lt;/span&gt;(emp) emp.Model.EmployeeID)

    &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; emp &lt;span class="kwrd"&gt;In&lt;/span&gt; allEmployees.Values
        &lt;span class="kwrd"&gt;If&lt;/span&gt; emp.Model.ReportsTo.HasValue &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            allEmployees(emp.Model.ReportsTo.Value).DirectReports.Add(emp)
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
    &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; rootEmployees = allEmployees.Values.
        Where(&lt;span class="kwrd"&gt;function&lt;/span&gt;(emp) &lt;span class="kwrd"&gt;Not&lt;/span&gt; emp.Model.ReportsTo.HasValue())
        
    
    rootEmployees.Dump
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; HierarchicalEmployee
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;(emp &lt;span class="kwrd"&gt;As&lt;/span&gt; Employee)
           Model = emp
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Model &lt;span class="kwrd"&gt;As&lt;/span&gt; Employee
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; DirectReports &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; List(Of HierarchicalEmployee)
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=ovio7JDBOu4:iC7zVonNFiA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=ovio7JDBOu4:iC7zVonNFiA:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=ovio7JDBOu4:iC7zVonNFiA:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=ovio7JDBOu4:iC7zVonNFiA:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=ovio7JDBOu4:iC7zVonNFiA:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=ovio7JDBOu4:iC7zVonNFiA:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=ovio7JDBOu4:iC7zVonNFiA:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=ovio7JDBOu4:iC7zVonNFiA:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=ovio7JDBOu4:iC7zVonNFiA:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=ovio7JDBOu4:iC7zVonNFiA:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/ovio7JDBOu4" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 
                        <category domain="/Post.aspx/Category/1">LINQ</category> 
                        <category domain="/Post.aspx/Category/10">Entity Framework</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Hierarchical-Trees-from-Flat-Tables-using-LINQ</feedburner:origLink></item>
                <item>
                      <title>Aggregate clause issues</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/KNDu-KTIkp4/Aggregate-clause-issues</link>
                      <pubDate>Tue, 04 Sep 2012 15:33:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22187</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Aggregate-clause-issues</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22187</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Aggregate-clause-issues</wfw:comment>
                      <description>&lt;p&gt;I was reviewing a &lt;a href="http://stackoverflow.com/questions/12264751/is-aggregate-fatally-flawed-because-each-into-clause-is-executed-separately/12266007#12266007"&gt;Stack Exchange message regarding the Aggregate clause&lt;/a&gt; in VB () where they found that the query was issuing multiple requests to the database and occasionally returning the entire database table to memory and using LINQ to Objects over the result. I also found that &lt;a href="http://weblogs.asp.net/fbouma/archive/2008/05/21/vb-net-beware-of-the-aggregate-keyword.aspx"&gt;Frans Bouma blogged about this back in 2008&lt;/a&gt; at&amp;#160; . Consider the following LINQ query over Northwind:&lt;/p&gt;  &lt;p&gt;Dim query = Aggregate o in Orders   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; into Sum(o.Freight),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Average(o.Freight),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Max(o.Freight)&lt;/p&gt;  &lt;p&gt;This produces the following TSQL Statements in EF. Notice here that the Sum and Avg are performed on the server, but the Max pulls the entire table to memory and does Max on the client. It would seem that this is an issue in the expression tree parser.&lt;/p&gt;  &lt;p&gt;SELECT   &lt;br /&gt;[GroupBy1].[A1] AS [C1]    &lt;br /&gt;FROM ( SELECT    &lt;br /&gt;&amp;#160;&amp;#160; SUM([Extent1].[Freight]) AS [A1]    &lt;br /&gt;&amp;#160;&amp;#160; FROM [dbo].[Orders] AS [Extent1]    &lt;br /&gt;)&amp;#160; AS [GroupBy1]&lt;/p&gt;  &lt;p&gt;&lt;b&gt;GO&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;SELECT   &lt;br /&gt;[GroupBy1].[A1] AS [C1]    &lt;br /&gt;FROM ( SELECT    &lt;br /&gt;&amp;#160;&amp;#160; AVG([Extent1].[Freight]) AS [A1]    &lt;br /&gt;&amp;#160;&amp;#160; FROM [dbo].[Orders] AS [Extent1]    &lt;br /&gt;)&amp;#160; AS [GroupBy1]&lt;/p&gt;  &lt;p&gt;&lt;b&gt;GO&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;SELECT   &lt;br /&gt;[Extent1].[OrderID] AS [OrderID],     &lt;br /&gt;[Extent1].[CustomerID] AS [CustomerID],     &lt;br /&gt;[Extent1].[EmployeeID] AS [EmployeeID],     &lt;br /&gt;[Extent1].[OrderDate] AS [OrderDate],     &lt;br /&gt;[Extent1].[RequiredDate] AS [RequiredDate],     &lt;br /&gt;[Extent1].[ShippedDate] AS [ShippedDate],     &lt;br /&gt;[Extent1].[ShipVia] AS [ShipVia],     &lt;br /&gt;[Extent1].[Freight] AS [Freight],     &lt;br /&gt;[Extent1].[ShipName] AS [ShipName],     &lt;br /&gt;[Extent1].[ShipAddress] AS [ShipAddress],     &lt;br /&gt;[Extent1].[ShipCity] AS [ShipCity],     &lt;br /&gt;[Extent1].[ShipRegion] AS [ShipRegion],     &lt;br /&gt;[Extent1].[ShipPostalCode] AS [ShipPostalCode],     &lt;br /&gt;[Extent1].[ShipCountry] AS [ShipCountry]    &lt;br /&gt;FROM [dbo].[Orders] AS [Extent1]&lt;/p&gt;  &lt;p&gt;For comparison, here’s the queries issued from LINQ to SQL:&lt;/p&gt;  &lt;p&gt;SELECT SUM([t0].[Freight]) AS [value]   &lt;br /&gt;FROM [Orders] AS [t0]    &lt;br /&gt;GO&lt;/p&gt;  &lt;p&gt;SELECT AVG([t0].[Freight]) AS [value]   &lt;br /&gt;FROM [Orders] AS [t0]    &lt;br /&gt;GO&lt;/p&gt;  &lt;p&gt;SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], [t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]   &lt;br /&gt;FROM [Orders] AS [t0]&lt;/p&gt;  &lt;p&gt;Interestingly, if you use From instead of Aggregate, the expression tree parsers seem to be able to handle this better. For example, the original query could be re-written as follows:&lt;/p&gt;  &lt;p&gt;Dim query = From o in Orders   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Group By key = 0     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; into Sum(o.Freight),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Average(o.Freight),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Max(o.Freight)&lt;/p&gt;  &lt;p&gt;This produces the following SQL (using LINQ to SQL):&lt;/p&gt;  &lt;p&gt;SELECT SUM([t1].[Freight]) AS [Sum], AVG([t1].[Freight]) AS [Average], MAX([t1].[Freight]) AS [Max]   &lt;br /&gt;FROM (    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SELECT @p0 AS [value], [t0].[Freight]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; FROM [Orders] AS [t0]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ) AS [t1]    &lt;br /&gt;GROUP BY [t1].[value]&lt;/p&gt;  &lt;p&gt;For the time being at least, I have to agree with Frans that it is best to avoid using the Aggregate keyword in VB when accessing a database. I’ll update this if I hear any updates that are on the horizon.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KNDu-KTIkp4:SlJ237KX6IQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KNDu-KTIkp4:SlJ237KX6IQ:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KNDu-KTIkp4:SlJ237KX6IQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=KNDu-KTIkp4:SlJ237KX6IQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KNDu-KTIkp4:SlJ237KX6IQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KNDu-KTIkp4:SlJ237KX6IQ:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KNDu-KTIkp4:SlJ237KX6IQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=KNDu-KTIkp4:SlJ237KX6IQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KNDu-KTIkp4:SlJ237KX6IQ:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=KNDu-KTIkp4:SlJ237KX6IQ:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/KNDu-KTIkp4" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 
                        <category domain="/Post.aspx/Category/1">LINQ</category> 
                        <category domain="/Post.aspx/Category/10">Entity Framework</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Aggregate-clause-issues</feedburner:origLink></item>
                <item>
                      <title>Unit testing and SMTP</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/KBFJvOtYSsg/Unit-testing-and-SMTP</link>
                      <pubDate>Wed, 22 Aug 2012 21:16:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22186</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Unit-testing-and-SMTP</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22186</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Unit-testing-and-SMTP</wfw:comment>
                      <description>&lt;p&gt;Over the past several years, I’ve become a fan of unit testing. I’m not a test-first/TDD zealot by any means, but have found the definite benefits of testing your custom business logic to assert that it does what you say it will. When going to a client who hasn’t done unit testing at all, I often find it hard enough to get them to start testing and don’t want to over burden their tests with mocking frameworks to abstract out some of the external dependencies. As a result, I have no qualms about incorporating both unit testing and integration testing into the mix here.&lt;/p&gt; &lt;p&gt;One of the things that can be tricky and time consuming to test is operations that send automatic emails via the SMTP server. If you send through a real server, the transmission can be a significant bottleneck from a performance standpoint, particularly if the server doesn’t actually exist. In the past, I’ve used local fake SMTP “servers” like the one at &lt;a title="http://smtp4dev.codeplex.com/" href="http://smtp4dev.codeplex.com/"&gt;http://smtp4dev.codeplex.com/&lt;/a&gt;. With this, you simply run the server in the start tray and any time you send an email to your localhost port 25, it will show up there. In your web config, you can specify this quickly by adding the following node for your test project.&lt;/p&gt;&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.net&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;mailSettings&lt;/span&gt;  &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;smtp&lt;/span&gt; &lt;span class="attr"&gt;deliveryMethod&lt;/span&gt;&lt;span class="kwrd"&gt;="Network"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;network&lt;/span&gt; &lt;span class="attr"&gt;host&lt;/span&gt;&lt;span class="kwrd"&gt;="127.0.0.1"&lt;/span&gt; &lt;span class="attr"&gt;port&lt;/span&gt;&lt;span class="kwrd"&gt;="25"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;smtp&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;mailSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.net&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;An even better solution is to change the DeliveryMethod attribute to “SpecifiedPickupDirectory” and then specify a local path that you want new emails to appear in. From your unit test, you can then check that folder for the presence of the new email if you want to confirm that it was “sent” and open it to view the contents. The revised configuration is as follows:&lt;/p&gt;&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.net&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;mailSettings&lt;/span&gt;  &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;smtp&lt;/span&gt; &lt;span class="attr"&gt;deliveryMethod&lt;/span&gt;&lt;span class="kwrd"&gt;="SpecifiedPickupDirectory"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;specifiedPickupDirectory&lt;/span&gt; &lt;span class="attr"&gt;pickupDirectoryLocation&lt;/span&gt;&lt;span class="kwrd"&gt;="d:\Temp\smtp"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;smtp&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;mailSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.net&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;One additional item I want to point out is that if you follow the &lt;a href="http://msdn.microsoft.com/en-us/library/ms164241.aspx"&gt;MSDN help for SpecifiedPickupDirectory&lt;/a&gt; you will currently get a warning if you use &lt;em&gt;DeliveryMethod=”specifiedPickupDirectory” &lt;/em&gt;with a lowercase “s”. Fortunately, VS will ignore the case on that attribute value and work either way.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KBFJvOtYSsg:PGYqp2146iI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KBFJvOtYSsg:PGYqp2146iI:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KBFJvOtYSsg:PGYqp2146iI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=KBFJvOtYSsg:PGYqp2146iI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KBFJvOtYSsg:PGYqp2146iI:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KBFJvOtYSsg:PGYqp2146iI:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KBFJvOtYSsg:PGYqp2146iI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=KBFJvOtYSsg:PGYqp2146iI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=KBFJvOtYSsg:PGYqp2146iI:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=KBFJvOtYSsg:PGYqp2146iI:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/KBFJvOtYSsg" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Unit-testing-and-SMTP</feedburner:origLink></item>
                <item>
                      <title>Async in loops</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/sTxDyarAZRU/Async-in-loops</link>
                      <pubDate>Tue, 21 Aug 2012 13:40:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22185</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Async-in-loops</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22185</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Async-in-loops</wfw:comment>
                      <description>&lt;p&gt;In &lt;a href="http://www.thinqlinq.com/Post.aspx/Title/Async-Await-StateMachine-in-ILSpy"&gt;yesterday’s post&lt;/a&gt;, I mentioned that there is a performance penalty of using the new Async/Await feature inside of loops. Today, I want to point out another reason why you might not want to use Async/Await inside of a loop. Consider the following example that takes a web page as a string and finds all of the hyperlinks contained in that page (using a regular expression match) and downloads each of those child pages. Using Tasks from the TPL we can load the child pages like this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;      &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; GetChildren(&lt;span class="kwrd"&gt;string&lt;/span&gt; parent)
        {
            var matches = Regex.Matches(parent, _HtmlRegex, RegexOptions.IgnoreCase);
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Match match &lt;span class="kwrd"&gt;in&lt;/span&gt; matches)
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (_CancelToken.IsCancellationRequested)
                    &lt;span class="kwrd"&gt;return&lt;/span&gt;;
                &lt;span class="kwrd"&gt;string&lt;/span&gt; childTarget = match.Groups[1].Value;
                WebClient client = &lt;span class="kwrd"&gt;new&lt;/span&gt; WebClient();
                Task&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; childTask = client.DownloadStringTaskAsync(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(childTarget));
                childTask.ContinueWith(child =&amp;gt;
                {
                    _FoundUrls.Add(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"{0} ({1})"&lt;/span&gt;, childTarget, child.Result.Length));
                },
                    TaskContinuationOptions.ExecuteSynchronously);
            }
            TaskButton.IsEnabled = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        }&lt;/pre&gt;
&lt;p&gt;Here we use the DownloadStringTaskAsync passing each found child page url. We use the ContinueWith method to chain operations asynchronously to download the child pages. As a first pass on this using Async/Await, we can simply await the task returner and no longer need the ContinueWith clause. Our code just continues as if it were just a straight code flow:&lt;/p&gt;&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; async &lt;span class="kwrd"&gt;void&lt;/span&gt; GetChildrenAsync(&lt;span class="kwrd"&gt;string&lt;/span&gt; parent)
        {
            var matches = Regex.Matches(parent, _HtmlRegex, RegexOptions.IgnoreCase);
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Match match &lt;span class="kwrd"&gt;in&lt;/span&gt; matches)
            {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (_CancelToken.IsCancellationRequested)
                    &lt;span class="kwrd"&gt;return&lt;/span&gt;;
                &lt;span class="kwrd"&gt;string&lt;/span&gt; childTarget = match.Groups[1].Value;
                WebClient client = &lt;span class="kwrd"&gt;new&lt;/span&gt; WebClient();
                &lt;span class="kwrd"&gt;string&lt;/span&gt; child = await client.DownloadStringTaskAsync(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(childTarget));
                _FoundUrls.Add(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"{0} ({1})"&lt;/span&gt;, childTarget, child.Length));
            }
            AsyncCtp2Button.IsEnabled = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;That sure looks cleaner. What’s the issue? The downside of await is that the code execution moves over to a background loop and stops executing until it receives a response. As a result, we loose the performance improvement of issuing multiple requests and processing them as they return. Although the UI thread can continue on, this background process is blocked until it completes. At which time we request the next page that was found.&lt;/p&gt;
&lt;p&gt;When writing multiple asynchronous requests, it is often better to use the WaitAny, WaitAll (for blocking operations), or WhenAll for non-blocking operations. Unfortunately, Async/Await only allow for operating on a single task, not a group of tasks. So how can we modify the code to issue multiple requests and operate on the results as they come back? We need to translate each of the requests into tasks and then return a Task of the resulting string arrays. Here’s the resulting code:&lt;/p&gt;&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; Task&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;[]&amp;gt; GetChildrenAsyncAll(&lt;span class="kwrd"&gt;string&lt;/span&gt; parent)
        {
            var matches = Regex.Matches(parent, _HtmlRegex, RegexOptions.IgnoreCase);
            var childTasks = matches.OfType&amp;lt;Match&amp;gt;()
                             .Select(match =&amp;gt; 
                                 {
                                     &lt;span class="kwrd"&gt;string&lt;/span&gt; childTarget = match.Groups[1].Value;
                                     var client = &lt;span class="kwrd"&gt;new&lt;/span&gt; WebClient();
                                     var childTask = client.DownloadStringTaskAsync(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(childTarget));
                                     childTask.ContinueWith(child =&amp;gt; 
                                         Dispatcher.BeginInvoke(&lt;span class="kwrd"&gt;new&lt;/span&gt; Action(() =&amp;gt; 
                                             _FoundUrls.Add(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"{0} ({1})"&lt;/span&gt;, childTarget, child.Result.Length)))));
                                     &lt;span class="kwrd"&gt;return&lt;/span&gt; childTask;
                                 });

            &lt;span class="kwrd"&gt;return&lt;/span&gt; Task.WhenAll(childTasks.ToArray());
       }&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
Ugh. That’s not quite as elegant. I never said async was easy. Async/Await do make the simple cases appear easier. However there are times where a bit more effort is needed to achieve the true results that you want. &lt;/p&gt;
&lt;p&gt;As always, if you have recommendations on how to improve this code, I’m always eager to learn ways to improve. If you want to try this sample yourself, feel free to &lt;a href="http://www.thinqlinq.com/Downloads/AsyncProgramming.zip"&gt;download the async project&lt;/a&gt; and kick the tires a bit. The download sample also includes a version using Rx if you want to compare that version as well.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=sTxDyarAZRU:zgjpoXy7Tno:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=sTxDyarAZRU:zgjpoXy7Tno:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=sTxDyarAZRU:zgjpoXy7Tno:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=sTxDyarAZRU:zgjpoXy7Tno:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=sTxDyarAZRU:zgjpoXy7Tno:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=sTxDyarAZRU:zgjpoXy7Tno:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=sTxDyarAZRU:zgjpoXy7Tno:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=sTxDyarAZRU:zgjpoXy7Tno:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=sTxDyarAZRU:zgjpoXy7Tno:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=sTxDyarAZRU:zgjpoXy7Tno:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/sTxDyarAZRU" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/8">C#</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Async-in-loops</feedburner:origLink></item>
                <item>
                      <title>Async Await StateMachine in ILSpy</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/13YimnJCg88/Async-Await-StateMachine-in-ILSpy</link>
                      <pubDate>Tue, 21 Aug 2012 04:17:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22184</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Async-Await-StateMachine-in-ILSpy</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22184</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Async-Await-StateMachine-in-ILSpy</wfw:comment>
                      <description>&lt;p&gt;In my &lt;a href="http://www.thinqlinq.com/Downloads/AsyncProgramming.zip"&gt;Async Programming in .Net&lt;/a&gt; talk I like to show what’s really happening under the covers with the new async/await keywords in VS 2012. To show this, I’m currently using &lt;a href="http://sharptoolbox.com/tools/ilspy"&gt;ILSpy&lt;/a&gt; instead of Reflector because it is free. I noticed an “issue” tonight when trying to locate the MoveNext method of the state machine generated class, but couldn’t find it. To begin, let’s look at the code sample.&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Module&lt;/span&gt; AsyncWorld
    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; DoWorkAsync()
        PrintIt()
        Console.ReadLine()
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; Async &lt;span class="kwrd"&gt;Sub&lt;/span&gt; PrintIt()
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; text = &lt;span class="str"&gt;"Hello World"&lt;/span&gt;
        Await Task.Factory.StartNew(
            &lt;span class="kwrd"&gt;Sub&lt;/span&gt;()
                Threading.Thread.Sleep(2000)
                Console.WriteLine(text)
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;)
        Console.WriteLine(&lt;span class="str"&gt;"Done"&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

&lt;span class="kwrd"&gt;End&lt;/span&gt; Module&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Ignoring the potential code smell of an Async Sub (async void in C#), let’s take a look at what IL Spy gives us out of the box for the generated classes:&lt;/p&gt;&lt;a href="http://www.thinqlinq.com/Images/9d12b669de33_15012/image.png"&gt;&lt;img title="image" alt="image" src="http://www.thinqlinq.com/Images/9d12b669de33_15012/image_thumb.png" width="652" height="404"&gt;&lt;/a&gt; 
&lt;p&gt;Here we can see that the generated closure is displayed with the contained Lambda, but the underlying state machine that manages the closure is missing. If you want to see the state machine, click on Tools – Options and uncheck the “Decompile async methods (async/await)” option.&amp;nbsp; &lt;/p&gt;&lt;a href="http://www.thinqlinq.com/Images/9d12b669de33_15012/image_3.png"&gt;&lt;img title="image" alt="image" src="http://www.thinqlinq.com/Images/9d12b669de33_15012/image_thumb_3.png" width="375" height="183"&gt;&lt;/a&gt; 
&lt;p&gt;Once you deselect that, refresh your project to see the compiler generated state machine:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.thinqlinq.com/Images/9d12b669de33_15012/image_4.png"&gt;&lt;img title="image" alt="image" src="http://www.thinqlinq.com/Images/9d12b669de33_15012/image_thumb_4.png" width="763" height="529"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;My, that’s a lot of code for our simple Console Writeline task. Can’t find it? It’s called in the line &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;taskAwaiter = Task.Factory.StartNew(New Action(Me.$VB$ResumableLocal_$VB$Closure_ClosureVariable_1$1._Lambda$__1)).GetAwaiter()&lt;/em&gt;. &lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Remember the closure we saw above? Our code’s still in there. The state machine just lets us call this asynchronously trapping for exceptions as necessary. In most cases, you don’t need to worry about all of this compiler generated code. You should be aware of it though if you are writing code with lots of awaits in a single method, particularly in tight loops. Your performance will suffer in those cases. It is better to work more natively with the TPL Task objects with continuations than using await/async in those cases. For more information, I highly recommend that you check out Steven Toub’s &lt;a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-829T"&gt;Zen of Async session&lt;/a&gt; from Build 2011. 
&lt;p&gt;If you want to try this out more, &lt;a href="http://www.thinqlinq.com/Downloads/AsyncProgramming.zip"&gt;download my async samples&lt;/a&gt; including comparative examples using Callbacks, APM, Tasks, Async/Await, and Reactive Extensions (Rx).&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=13YimnJCg88:Lks5q7SSe74:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=13YimnJCg88:Lks5q7SSe74:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=13YimnJCg88:Lks5q7SSe74:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=13YimnJCg88:Lks5q7SSe74:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=13YimnJCg88:Lks5q7SSe74:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=13YimnJCg88:Lks5q7SSe74:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=13YimnJCg88:Lks5q7SSe74:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=13YimnJCg88:Lks5q7SSe74:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=13YimnJCg88:Lks5q7SSe74:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=13YimnJCg88:Lks5q7SSe74:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/13YimnJCg88" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Async-Await-StateMachine-in-ILSpy</feedburner:origLink></item>
                <item>
                      <title>SignalR and Reactive Extensions are an Rx for server push notifications</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/WqKw2t3_Jj8/SignalR-and-Reactive-Extensions-are-an-Rx-for-server-push-notifications</link>
                      <pubDate>Mon, 30 Jul 2012 02:18:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22183</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/SignalR-and-Reactive-Extensions-are-an-Rx-for-server-push-notifications</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22183</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/SignalR-and-Reactive-Extensions-are-an-Rx-for-server-push-notifications</wfw:comment>
                      <description>&lt;p&gt;Recently, I had the need to build a system where multiple clients needed to be notified as changes happened on the server. While watching Damian Edwards, Brad Wilson and Levi Broderick present on &lt;a href="http://channel9.msdn.com/Events/aspConf/aspConf/Async-in-ASP-NET"&gt;Async in ASP.Net during the AspConf&lt;/a&gt; I was introduced to the dynamic simplicity that &lt;a href="http://signalr.net/"&gt;SignalR&lt;/a&gt; brings to the table. I was even more intrigued by the fact that it integrates directly with IObservable and the Reactive Extensions. After using it for a week, I’m truly impressed by what they’ve done with this library. To give you an idea of what I mean, let’s take my ObservableSensor demo which generates random values and see how we can use SignalR to expose these values over a distributed client environment.&lt;/p&gt;  &lt;h3&gt;Reactive Extensions on the Server&lt;/h3&gt;  &lt;p&gt;To begin, let’s look at the server. Here we will use the Observable.Generate method to generate some random values with associated random categories and the timestamp when the value was generated:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Option&lt;/span&gt; Strict Off

&lt;span class="kwrd"&gt;Imports&lt;/span&gt; Microsoft.VisualBasic
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Reactive.Linq
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; SignalR

&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; ObservableSensor

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;()
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; rand = &lt;span class="kwrd"&gt;New&lt;/span&gt; Random(Now.Millisecond)

        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; Generator = Observable.Generate(Of &lt;span class="kwrd"&gt;Double&lt;/span&gt;, SensorData)(
            initialState:=0,
            condition:=&lt;span class="kwrd"&gt;Function&lt;/span&gt;(val) &lt;span class="kwrd"&gt;True&lt;/span&gt;,
            iterate:=&lt;span class="kwrd"&gt;Function&lt;/span&gt;(val) rand.NextDouble,
            resultSelector:=&lt;span class="kwrd"&gt;Function&lt;/span&gt;(val) &lt;span class="kwrd"&gt;New&lt;/span&gt; SensorData &lt;span class="kwrd"&gt;With&lt;/span&gt; 
                                          {
                                              .Time = Now,
                                              .Value = val * 20,
                                              .Category = (&lt;span class="kwrd"&gt;CInt&lt;/span&gt;(val * 4)).ToString()
                                          },
            timeSelector:=&lt;span class="kwrd"&gt;Function&lt;/span&gt;(val) TimeSpan.FromSeconds(val))

        Generator.Subscribe(&lt;span class="kwrd"&gt;Sub&lt;/span&gt;(value)
                                &lt;span class="kwrd"&gt;Dim&lt;/span&gt; context = GlobalHost.ConnectionManager.GetHubContext(Of ObservableSensorHub)()
                                context.Clients.Broadcast(value)
                            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;)
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt;

&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; SensorData
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Time &lt;span class="kwrd"&gt;As&lt;/span&gt; DateTime
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Category &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; Value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Double&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;If you recall, we &lt;a href="http://www.thinqlinq.com/Post.aspx/Title/Revising-the-Reactive-Sensor-Generator"&gt;discussed the Observable.Generate&lt;/a&gt; implementation last year. The new part here occurs in the Subscribe implementation. &lt;/p&gt;

&lt;h3&gt;SignalR across the tiers&lt;/h3&gt;

&lt;p&gt;In this case, we are going to “Broadcast” our newly created methods to anyone listening. In this case, we are publishing our notifications without having a direct connection to the SignalR hub. We can grab a hold of it using the GlobalHost ConnectionManager to get the hub in our AppDomain for a type of ObservableSensorHub. What is this Hub thing you may ask. Well, here is the implementation for the ObservableSensorHub:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; SignalR.Hubs

&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; ObservableSensorHub
    &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; Hub

&lt;span class="kwrd"&gt;End&lt;/span&gt; Class&lt;/pre&gt;

&lt;p&gt;In case you’re wondering, no I’m not missing code here. That’s the complete implementation. We’re just creating a strongly typed instance of the SignalR.Hubs.Hub type for the the ConnectionManager to work with. In this simple application, we’re just going to start generating values when the web application starts. In the Global.asax, add the following implementation:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Application_Start(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt;, &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; EventArgs)
        Sensor = &lt;span class="kwrd"&gt;New&lt;/span&gt; ObservableSensor
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;At this point, we now have a server that can broadcast our random values over HTTP to any clients that wish to subscribe. Before moving to the client, I need to say a bit more about the Broadcast “Method” that we are calling on on the Hub’s Clients. If you look at the type definition of Clients, you will see that there is no Broadcast method. Clients is actually a Dynamic object. At run time, we are declaring that it has a method called Broadcast. The SignalR infrastructure then knows how to translate requests for an invocation method by that name into an HTTP message to be sent to any clients (serializing the results into a JSON object using Json.Net). Remember in Visual Basic, we enable the Dynamic functionality by specifying &lt;em&gt;Option Strict Off&lt;/em&gt; at the top of our class definition.&lt;/p&gt;

&lt;p&gt;Now how do we consume these messages? Let’s start with a console application. First, make sure that you’ve installed and added the references to the SignalR.Client library. The easiest way is to use NuGet. Rather than a bunch of text, let’s just jump to the code:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Option&lt;/span&gt; Strict Off

&lt;span class="kwrd"&gt;Imports&lt;/span&gt; SignalR.Client.Hubs
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Reactive.Linq
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; Newtonsoft.Json.Linq

&lt;span class="kwrd"&gt;Module&lt;/span&gt; Module1

    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; Main()
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; cn = &lt;span class="kwrd"&gt;New&lt;/span&gt; HubConnection(&lt;span class="str"&gt;&amp;quot;http://localhost:5687/&amp;quot;&lt;/span&gt;)
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; sensor = cn.CreateProxy(&lt;span class="str"&gt;&amp;quot;observableSensorHub&amp;quot;&lt;/span&gt;)

        sensor.&lt;span class="kwrd"&gt;On&lt;/span&gt;(Of SensorData)(&lt;span class="str"&gt;&amp;quot;broadcast&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;Sub&lt;/span&gt;(item) Console.WriteLine(item.Value))

        cn.Start().Wait()
        Console.ReadLine()

    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

&lt;span class="kwrd"&gt;End&lt;/span&gt; Module&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Here, we create a new HubConnection specifying the endpoint for our web application. SignalR does support self hosted servers if you want to use a Windows Service or other back end implementation. As long as the client can see the server over the network, you can wire it up. Second, we create a dynamic proxy specifying the hub type that we created on the server. Note here that the casing of the proxy is important and uses Camel casing even though the implementation on the server used Pascal casing. This is done to make the hubs and methods feel more natural to JavaScript clients.&lt;/p&gt;

&lt;p&gt;Next, we specify how to handle the push notifications that the server sends. We do that using the .On method, specifying the type (SensorData) that the method should be deserialized back into. We then specify the name of the method (altering the case as mentioned above) that we are listening for along with the Action that should be invoked as each value is received. In this case, we’ll just output the value that we received to the console window. &lt;/p&gt;

&lt;h3&gt;RX in the Client&lt;/h3&gt;

&lt;p&gt;At this point we have Rx pushing messages to the client via SignalR. Let’s take it a step further and add some Rx goodness on the client side as well. In addition to the On method, the Proxy also supports an Observe method which turns the message pump into an IObservable of an array of Objects where each of the method parameters are contained in that array. Since our Broadcast method only has a single parameter of type SensorData, we will grab it by getting the first array element and calling the Json.Net .ToObject implementation to translate it back into our strongly typed object. From there, we work with it just as we would any other Observable sequence. For example, to output only the generated values for Category 1, we could use the following:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; cn = &lt;span class="kwrd"&gt;New&lt;/span&gt; HubConnection(&lt;span class="str"&gt;&amp;quot;http://localhost:5687/&amp;quot;&lt;/span&gt;)
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; sensor = cn.CreateProxy(&lt;span class="str"&gt;&amp;quot;observableSensorHub&amp;quot;&lt;/span&gt;)

        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; items = From item &lt;span class="kwrd"&gt;In&lt;/span&gt; sensor.Observe(&lt;span class="str"&gt;&amp;quot;broadcast&amp;quot;&lt;/span&gt;)
                    &lt;span class="kwrd"&gt;Let&lt;/span&gt; instance = item(0).ToObject(Of SensorData)()
                    Where instance.Category = &lt;span class="str"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;Select&lt;/span&gt; instance

        Using items.Subscribe(&lt;span class="kwrd"&gt;Sub&lt;/span&gt;(value) Console.WriteLine(value.Value))

            cn.Start().Wait()
            Console.ReadLine()

        &lt;span class="kwrd"&gt;End&lt;/span&gt; Using&lt;/pre&gt;

&lt;p&gt;In this case, we Start the connection inside of our subscription’s Using clause along with the Console.ReadLine. Once a key is pressed, the subscription is disposed freeing our resource.&lt;/p&gt;

&lt;p&gt;One of the nice things is the flexibility that SignalR offers. Pretty much anything that speaks HTTP can consume these messages from our Rx Server. If we wanted to consume the same messages in a web client, we could use the following Javascript code:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;      $(function () {
          &lt;span class="rem"&gt;// Proxy created on the fly&lt;/span&gt;
          var hub = $.connection.observableSensorHub;

          &lt;span class="rem"&gt;// Declare a function on the chat hub so the server can invoke it&lt;/span&gt;
          hub.Broadcast = function (&lt;span class="kwrd"&gt;value&lt;/span&gt;) {
              $(&lt;span class="str"&gt;'#values'&lt;/span&gt;).append(&lt;span class="str"&gt;'&amp;amp;lt;li&amp;amp;gt;'&lt;/span&gt; + &lt;span class="kwrd"&gt;value&lt;/span&gt;.Time + &lt;span class="str"&gt;': '&lt;/span&gt; + &lt;span class="kwrd"&gt;value&lt;/span&gt;.Value + &lt;span class="str"&gt;'&amp;amp;lt;/li&amp;amp;gt;'&lt;/span&gt;);
          };

          &lt;span class="rem"&gt;// Start the connection&lt;/span&gt;
          $.connection.hub.start();
      });&lt;/pre&gt;

&lt;p&gt;In the javascript, we connect to our server by referring to the $.connection.observableSensorHub. Notice the camel cased name here? That’s the SignalR translation in action again. We then specify the method handler for the dynamically invoked “Broadcast” method. Here we just add list item entries to the unordered list.&lt;/p&gt;

&lt;p&gt;As I said above, I’m so impressed with SignalR so far. Don’t be surprised to see me post more about it in the future. For now however, if you want feel free to &lt;a href="http://www.ThinqLinq.com/downloads/RxSignalr.zip"&gt;download this sample&lt;/a&gt; and try it out yourself. You will need to refresh the nuget packages to get it to run. Additionally, realize that the sample was built with RC builds of Visual Studio 2012, Rx 2.0, and SignalR. I don’t guarantee that the sample will continue to work once these are officially released. If you notice any issues or want to see more details, let me know what you Thinq below.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WqKw2t3_Jj8:PSLtOjfNKUg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WqKw2t3_Jj8:PSLtOjfNKUg:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WqKw2t3_Jj8:PSLtOjfNKUg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=WqKw2t3_Jj8:PSLtOjfNKUg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WqKw2t3_Jj8:PSLtOjfNKUg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WqKw2t3_Jj8:PSLtOjfNKUg:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WqKw2t3_Jj8:PSLtOjfNKUg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=WqKw2t3_Jj8:PSLtOjfNKUg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WqKw2t3_Jj8:PSLtOjfNKUg:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=WqKw2t3_Jj8:PSLtOjfNKUg:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/WqKw2t3_Jj8" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 
                        <category domain="/Post.aspx/Category/24">Rx</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/SignalR-and-Reactive-Extensions-are-an-Rx-for-server-push-notifications</feedburner:origLink></item>
                <item>
                      <title>ThinqLinq Updated to MVC 4</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/Hy_uu106fsk/ThinqLinq-Updated-to-MVC-4</link>
                      <pubDate>Tue, 24 Jul 2012 03:39:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22182</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/ThinqLinq-Updated-to-MVC-4</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22182</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/ThinqLinq-Updated-to-MVC-4</wfw:comment>
                      <description>&lt;p&gt;As I work more in Visual Studio 2012, I found the need to make a small tweak to this web site, but discovered that the MVC 1 code base that the site was using is no longer a natively supported as part of Visual Studio 2012.&amp;#160; As a result, I took the plunge and re-wrote the UI portions of the site using &lt;strike&gt;MVC3&lt;/strike&gt; MVC 4 with the new Razor templating engine. This site is a test-bed of technologies I want to play with anyway. I also upgraded the site from .Net 3.5 to .Net 4. In light of these changes, please let me know if you see anything unexpected on the site. &lt;/p&gt;  &lt;p&gt;I’m also in the process of revising the comment system from the home-grown version I was using, to a hosted comment system in the hopes to get more conversation going on the site. Feel free to comment using the new commenting system. If you have problems with the comments, please feel free to let me know on the &lt;a href="http://www.thinqlinq.com/Contact.aspx"&gt;Contact&lt;/a&gt; page. Thank you for your ongoing support.&lt;/p&gt;  &lt;p&gt;Edit. Thanks to Amit Patel’s article, I was able to &lt;a href="http://www.c-sharpcorner.com/UploadFile/amit12345/how-to-upgrade-mvc-3-to-mvc4/"&gt;upgrade from MVC 3 to MVC 4&lt;/a&gt; in less than 30 minutes (including deployment). I hope you appreciate the effort.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=Hy_uu106fsk:tn40nsXpH3E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=Hy_uu106fsk:tn40nsXpH3E:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=Hy_uu106fsk:tn40nsXpH3E:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=Hy_uu106fsk:tn40nsXpH3E:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=Hy_uu106fsk:tn40nsXpH3E:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=Hy_uu106fsk:tn40nsXpH3E:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=Hy_uu106fsk:tn40nsXpH3E:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=Hy_uu106fsk:tn40nsXpH3E:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=Hy_uu106fsk:tn40nsXpH3E:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=Hy_uu106fsk:tn40nsXpH3E:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/Hy_uu106fsk" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/21">MVC</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/ThinqLinq-Updated-to-MVC-4</feedburner:origLink></item>
                <item>
                      <title>Windows 8 Live Tiles and LINQ to XML</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/jbLHbpRV69Q/Windows-8-Live-Tiles-and-LINQ-to-XML</link>
                      <pubDate>Sun, 22 Jul 2012 22:29:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22181</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Windows-8-Live-Tiles-and-LINQ-to-XML</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22181</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Windows-8-Live-Tiles-and-LINQ-to-XML</wfw:comment>
                      <description>&lt;p&gt;When I started working with Windows 8 Metro development, I was disappointed to see that the native WinRT API’s relied on the older XmlDocument and XMLDom rather than the newer subset of XDocument/XElement and LINQ to XML. I suppose this was necessary because the older version was more natural for C++ and JavaScript options for Metro applications. If you’re like me and want to use LINQ to XML to work with XML in WinRT, all you need to do is pass the XML strings back and forth between your C#/VB code and the native WinRT methods.&lt;/p&gt;  &lt;p&gt;Let’s consider the case of custom Tile Notifications. In order to set one, you first get the XML template from the TileUpdateManager. This returns an XmlDocument object with an XML template looking like this: &lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;visual&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;template&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TileWidePeekImage01&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;text&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;text&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;visual&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;tile&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;In order to set the text, we need to locate the “text” element with the attribute id of 1 and set the value. While we could create the Xml from scratch, It might be safer to just set the node’s value and retain the rest of the XML. If you’ve been following my blog for any time, I find the LINQ to XML API’s to be much easier to use than the older XmlDom. Luckily, moving back and forth from XmlDom and XDocument is as simple as calling Parse on the XDocument passing in the .GetXml method of the XmlDocument. To push our changed XDocument back into the XmlDocument, we call LoadXml passing the String representation of the XDocument using ToString. Here’s the code to grab the TileSquareText04 template and set the text value to “Text Line 1”. 

&lt;br /&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareText04)

&lt;span class="rem"&gt;' Transition to XDocument&lt;/span&gt;
&lt;span class="kwrd"&gt;Dim&lt;/span&gt; xTile = XDocument.Parse(tileXml.GetXml())
&lt;span class="rem"&gt;' Manipulate with LINQ to XML&lt;/span&gt;
xTile...&amp;lt;text&amp;gt;.FirstOrDefault(&lt;span class="kwrd"&gt;Function&lt;/span&gt;(node) node.@id = &lt;span class="str"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;).SetValue(&lt;span class="str"&gt;&amp;quot;Text Line 1&amp;quot;&lt;/span&gt;)

&lt;span class="rem"&gt;' Set XmlDocument&lt;/span&gt;
tileXml.LoadXml(xTile.ToString())
&lt;span class="kwrd"&gt;Dim&lt;/span&gt; notification = &lt;span class="kwrd"&gt;New&lt;/span&gt; TileNotification(tileXml)
TileUpdateManager.CreateTileUpdaterForApplication().Update(notification)&lt;/pre&gt;

&lt;p&gt;That’s all it takes. If you don’t like this template, there’s plenty more where this came from. MSDN has a great &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868263.aspx"&gt;page showing each of the tile samples&lt;/a&gt; along with the template XML you need to use.&lt;/p&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=jbLHbpRV69Q:RMiwFUh8Z9s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=jbLHbpRV69Q:RMiwFUh8Z9s:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=jbLHbpRV69Q:RMiwFUh8Z9s:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=jbLHbpRV69Q:RMiwFUh8Z9s:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=jbLHbpRV69Q:RMiwFUh8Z9s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=jbLHbpRV69Q:RMiwFUh8Z9s:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=jbLHbpRV69Q:RMiwFUh8Z9s:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=jbLHbpRV69Q:RMiwFUh8Z9s:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=jbLHbpRV69Q:RMiwFUh8Z9s:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=jbLHbpRV69Q:RMiwFUh8Z9s:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/jbLHbpRV69Q" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/18">Linq to XML</category> 
                        <category domain="/Post.aspx/Category/27">WinRT</category> 
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Windows-8-Live-Tiles-and-LINQ-to-XML</feedburner:origLink></item>
                <item>
                      <title>Reactive Extensions books</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/WyI7cY9pKwI/Reactive-Extensions-books</link>
                      <pubDate>Fri, 06 Jul 2012 14:49:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22180</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Reactive-Extensions-books</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22180</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Reactive-Extensions-books</wfw:comment>
                      <description>&lt;p&gt;I’ve been presenting on Rx for some time know. Often I’m asked when I’m going to write another book. I’ve considered writing one on Rx expanding on my blog posts here, but suspected that the market might be a bit small. At this point there are two books on the market for Rx. The first one is free and serves as a good resource to the Rx methods.&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="688"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;         &lt;p&gt;&lt;a href="http://www.amazon.com/gp/product/B008GM3YPM/ref=as_li_qf_sp_asin_il?ie=UTF8&amp;amp;tag=woolswond-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=B008GM3YPM"&gt;&lt;img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;amp;Format=_SL110_&amp;amp;ASIN=B008GM3YPM&amp;amp;MarketPlace=US&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;tag=woolswond-20&amp;amp;ServiceVersion=20070822" /&gt;&lt;/a&gt;&lt;img style="border-bottom-style: none !important; margin: 0px; border-left-style: none !important; border-top-style: none !important; border-right-style: none !important" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=woolswond-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=B008GM3YPM" width="1" height="1" /&gt; &lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="486"&gt;Lee Campbell’s Introduction to Rx is a good overview of the various Reactive Extensions methods and coding techniques. It doesn’t focus as much on the practical uses of Rx, but would serve as a good companion to anyone trying to determine which method they should use for any given need. Even better, it’s free online at &lt;a href="http://www.introtorx.com"&gt;www.introtorx.com&lt;/a&gt; or for &lt;a href="http://www.amazon.com/Introduction-to-Rx-ebook/dp/B008GM3YPM/ref=sr_1_1?ie=UTF8&amp;amp;qid=1341584211&amp;amp;sr=8-1&amp;amp;keywords=introduction+to+rx"&gt;$0.99 at Amazon&lt;/a&gt;.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;&lt;a href="http://www.amazon.com/gp/product/1430237473/ref=as_li_qf_sp_asin_il?ie=UTF8&amp;amp;tag=woolswond-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1430237473"&gt;&lt;img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&amp;amp;Format=_SL110_&amp;amp;ASIN=1430237473&amp;amp;MarketPlace=US&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;tag=woolswond-20&amp;amp;ServiceVersion=20070822" /&gt;&lt;/a&gt;&lt;img style="border-bottom-style: none !important; margin: 0px; border-left-style: none !important; border-top-style: none !important; border-right-style: none !important" border="0" alt="" src="http://www.assoc-amazon.com/e/ir?t=woolswond-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1430237473" width="1" height="1" /&gt; &lt;/td&gt;        &lt;td valign="top" width="486"&gt;Jesse Liberty and Paul Betts released the first book (mostly) dedicated to Rx. It offers more practical examples, including a discussion of how to use Paul’s ReactiveUI MVVM implementation. I was hoping to like this book, but was disappointed by the thoroughness of covering Rx itself. Instead they used nearly a third of their 150 pages discussing C# LINQ features and LINQ to SQL for the Windows Phone. If you are already familiar with the basics or have gone through the free HOL below, you will probably want to skip directly to Lee’s book above. If you aren’t familiar with LINQ and Lambda’s this is a good book to start with as it covers the basics as well. It’s also a fairly short book as I read the entire thing on a single plane trip from Seattle to Atlanta.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;&amp;nbsp;&lt;/td&gt;        &lt;td valign="top" width="486"&gt;A couple of hands on Labs may be your best be to getting your feet wet and understanding the basics of Rx: &lt;a href="http://go.microsoft.com/fwlink/?LinkId=208528"&gt;Curing the asynchronous blues with the Reactive Extensions for .NET&lt;/a&gt; and &lt;a href="http://go.microsoft.com/fwlink/?LinkId=208527"&gt;JavaScript&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In addition to these books, I still recommend the learning resources mentioned in my post: &lt;a href="http://www.thinqlinq.com/Post.aspx/Title/Reactive-Framework-Learning-Resources-for-RxNet-and-RxJS"&gt;Reactive Framework Learning Resources for RxNet and RxJS&lt;/a&gt;. I still wonder if there is a market for more books on Rx. What do you Thinq?&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WyI7cY9pKwI:Bym39fxa8-Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WyI7cY9pKwI:Bym39fxa8-Q:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WyI7cY9pKwI:Bym39fxa8-Q:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=WyI7cY9pKwI:Bym39fxa8-Q:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WyI7cY9pKwI:Bym39fxa8-Q:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WyI7cY9pKwI:Bym39fxa8-Q:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WyI7cY9pKwI:Bym39fxa8-Q:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=WyI7cY9pKwI:Bym39fxa8-Q:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=WyI7cY9pKwI:Bym39fxa8-Q:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=WyI7cY9pKwI:Bym39fxa8-Q:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/WyI7cY9pKwI" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/24">Rx</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Reactive-Extensions-books</feedburner:origLink></item>
                <item>
                      <title>LINQ to Database Performance hints</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/_6Vg2RQRkwo/LINQ-to-Database-Performance-hints</link>
                      <pubDate>Tue, 12 Jun 2012 19:04:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22179</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/LINQ-to-Database-Performance-hints</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22179</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/LINQ-to-Database-Performance-hints</wfw:comment>
                      <description>&lt;p&gt;Although I’ve been writing primarily about RX here for a while, I still dig into some good old LINQ to SQL / EF quite a bit. Along the way, I’m frequently finding more tidbits to throw in the toolbox and thought I’d share some observations from a recent performance tuning project. (I’ll avoid disclosing the client and will change the database model to Northwind for this discussion protect the guilty.) &lt;/p&gt;  &lt;p&gt;In this project, I was brought in at the end of the project as things started going south to try to get it across the finish line. As with many projects, they waited until after the development was complete before they started to consider the performance impact of their code. This violates one of the principal tenants of performance testing: &lt;/p&gt;  &lt;h4&gt;RULE 1: Test early and often&lt;/h4&gt;  &lt;p&gt;Performance for larger scale apps needs to be considered from the beginning of the project and measured. If you don’t have an ongoing way of measuring the performance as the application progresses through the development lifecycle, you will find it difficult to pinpoint specific performance bottlenecks over time. &lt;/p&gt;  &lt;p&gt;As an example, several years ago I met with core members of the Microsoft CLR team. They shared the fact that they compare performance on each night’s builds and if they find more than a couple microsecond deviations in the performance, the teams were required to identify the source of the performance degradation. When working with systems that have millions of lines of code, if the waited a week, it may become hard to impossible to identify the multiple places where performance has now dropped by 1/100th of a second. Over time these performance penalties build up. &lt;/p&gt;  &lt;p&gt;I don’t mean to indicate that your Mom &amp;amp; Pop web site needs to live up to this stringent of a testing standard. Also, I’m not insinuating that you should prematurely over optimize your code, but try to make intelligent decisions and have ways of determining when your decisions negatively impact your performance up front.&lt;/p&gt;  &lt;p&gt;Why do I bring this up in the context of LINQ to DB (SQL/EF)? If you’re not testing and monitoring your app, you may find that a nice abstraction layer that you added just killed your performance. In the case of the client’s application, they had nicely abstracted away the ability to load various database structures into a generic repository. They had separate methods to GetCustomerById, GetOrdersForCustomerId, GetOrderDetailsForOrderId, etc. They also had helper methods for validation including ValidateIsCustomerNameUnique. The downside here is that reading through the code, it wasn’t easy to notice where hidden database calls were being sprinkled through the code. This brings up rule number 2 for performance testing with databases:&lt;/p&gt;  &lt;h4&gt;RULE 2: Profile your application&lt;/h4&gt;  &lt;p&gt;Profiling your application for external requests, including services is essential to make sure the requests you are making are not causing a performance bottleneck. I highly recommend using some sort of profiling tool, particularly for people who are new to LINQ. LINQ makes it easy to make silly mistakes like n+1 requests to a database when navigating lazy-loaded parent-child relationships. &lt;/p&gt;  &lt;p&gt;There are plenty of options for profiling applications. I identified some of them back in my &lt;a href="http://www.thinqlinq.com/Post.aspx/Title/linq-tools"&gt;LINQ Tools&lt;/a&gt; post. Some of these require adding code to your assemblies, while others simply attach to running processes. &lt;/p&gt;  &lt;p&gt;If you have a license for SQL Server, you probably have access to &lt;a href="http://msdn.microsoft.com/en-us/library/ms181091.aspx"&gt;SQL Profiler&lt;/a&gt;. To use this tool, create a new profile pointing it to your database and run your application. Once you have executed the code you want to profile, you can view all of the requests made against that database. Pay particular attention to cases where the same SQL is issued multiple times in succession or sequence. The downside here is that you will need to manually trace through your code base to find where each request is made in order to fix the issues.&lt;/p&gt;  &lt;p&gt;Another alternative if you have the Ultimate SKU of Visual Studio is to use the &lt;a href="http://msdn.microsoft.com/en-us/library/dd264915.aspx"&gt;Intellitrace&lt;/a&gt; feature added in Visual Studio 2010. Using Intellitrace, you can not only identify which SQL requests were issued to the database. You can also select each line in the results and navigate to the line of code that caused the request to be issued. Let’s consider this fairly innocuous code snippet to output the Order date and Product Names associated with each order:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;Using model &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; NwindEntities&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; o &lt;span class="kwrd"&gt;In&lt;/span&gt; model.Orders.Take(3)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        Console.WriteLine(o.OrderDate)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;        &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; od &lt;span class="kwrd"&gt;In&lt;/span&gt; o.Order_Details&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;            Console.WriteLine(od.Product.ProductName)&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;Next&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    &lt;span class="kwrd"&gt;Next&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; Using&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Running this and putting a breakpoint on line 8, we can see the following Intellitrace output:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.thinqlinq.com/Images/LINQ-Performance_BC91/image.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.thinqlinq.com/Images/LINQ-Performance_BC91/image_thumb.png" width="465" height="348" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, we can see that as we iterate each order item, we are making a separate request to the database&amp;#160; for each associated order detail record to get the related product object. Clicking on any of the lines of the output will take you directly to the line of the code that the request was made. Unfortunately, you won’t be able to view the parameters for each request using Intellitrace as you could with SQL Profiler, but that’s less important from a performance tuning perspective than it is to know that you have multiple excessive requests to the database. If you find that the intellitrace output becomes cluttered with non-database related trace items, I often find it helpful to filter the results to only ADO.Net requests:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.thinqlinq.com/Images/LINQ-Performance_BC91/image_3.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.thinqlinq.com/Images/LINQ-Performance_BC91/image_thumb_3.png" width="244" height="156" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fortunately, fixing the code above only requires changing line 2 in the code above to eagerly load the child records:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; o &lt;span class="kwrd"&gt;In&lt;/span&gt; model.Orders.Include(&lt;span class="str"&gt;&amp;quot;Order_Details&amp;quot;&lt;/span&gt;).Include(&lt;span class="str"&gt;&amp;quot;Order_Details.Product&amp;quot;&lt;/span&gt;).Take(3)&lt;/pre&gt;

&lt;p&gt;We may want to further optimize this request by not hydrating the entire objects, but rather just fetching the rows that we want as well:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Using model &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; NwindEntities
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; query = From o &lt;span class="kwrd"&gt;In&lt;/span&gt; model.Orders
                &lt;span class="kwrd"&gt;Select&lt;/span&gt; o.OrderDate,
                    ProductNames = From od &lt;span class="kwrd"&gt;In&lt;/span&gt; o.Order_Details
                                   &lt;span class="kwrd"&gt;Select&lt;/span&gt; od.Product.ProductName

    &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; o &lt;span class="kwrd"&gt;In&lt;/span&gt; query.Take(3)
        Console.WriteLine(o.OrderDate)
        &lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; p &lt;span class="kwrd"&gt;In&lt;/span&gt; o.ProductNames
           Console.WriteLine(p)
        &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    &lt;span class="kwrd"&gt;Next&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Using&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;If you don’t have access to SQL Profiler or Intellitrace, consider one of the other relatively inexpensive profiling tools out there like the &lt;a href="http://miniprofiler.com/"&gt;MVC MiniProfiler&lt;/a&gt;, &lt;a href="http://www.ormprofiler.com/"&gt;ORM Profiler&lt;/a&gt;,&amp;#160; &lt;a href="http://www.huagati.com/L2SProfiler/"&gt;Huagati’s LINQ to SQL Profiler&lt;/a&gt;, &lt;a href="http://www.efprof.com/"&gt;EF Prof&lt;/a&gt;, or at a bare minimum checking the generated code for your queries using &lt;a href="http://www.linqpad.net"&gt;LinqPad&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;With your application now profiled, hopefully you won’t run into the issues such as found in the following code (which I did see in the customer’s app changing the model to again protect the guilty:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Debug.WriteLine(Customers.FirstOrDefault().CompanyName)
Debug.WriteLine(Customers.FirstOrDefault().ContactName)
Debug.WriteLine(Customers.FirstOrDefault().ContactTitle)
Debug.WriteLine(Customers.FirstOrDefault().Phone)
Debug.WriteLine(Customers.FirstOrDefault().Fax)
&lt;span class="kwrd"&gt;Dim&lt;/span&gt; CustomerOrders = Customers.FirstOrDefault().Orders
&lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; order &lt;span class="kwrd"&gt;in&lt;/span&gt; CustomerOrders
    &lt;span class="rem"&gt;' Load the order into a POCO&lt;/span&gt;
Next&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;/pre&gt;

&lt;p&gt;Quick quiz boys and girls, without using a profiler how many requests are we making to our database here? Remember that not only will you have a database hit for each call to FirstOrDefault which doesn’t use deferred loading, but you’ll also get a call on GetEnumerator (called internally in the For Each iteration). Thus the count is 7 for the above code, right? Actually, it’s worse because hidden behind the Debug.WriteLine is a trace writer which also writes the value to the database’s log table. As a result we actually have 12 database requests (7 reads and 5 writes) instead of the single query that we should have used. In this case we’re breaking rule #3:&lt;/p&gt;

&lt;h4&gt;RULE 3: Don’t fetch needlessly&lt;/h4&gt;

&lt;p&gt;In the above code, we can simply fetch our target customer once and automatically include their associated Orders as follows:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; firstCustomer = Customers.Include(&lt;span class="str"&gt;&amp;quot;Orders&amp;quot;&lt;/span&gt;).FirstOrDefault()
Debug.WriteLine(firstCustomer.CompanyName)
Debug.WriteLine(firstCustomer.ContactName)
Debug.WriteLine(firstCustomer.ContactTitle)
Debug.WriteLine(firstCustomer.Phone)
Debug.WriteLine(firstCustomer.Fax)
&lt;span class="kwrd"&gt;Dim&lt;/span&gt; CustomerOrders = firstCustomer.Orders
&lt;span class="kwrd"&gt;For&lt;/span&gt; &lt;span class="kwrd"&gt;Each&lt;/span&gt; order &lt;span class="kwrd"&gt;in&lt;/span&gt; CustomerOrders
    &lt;span class="rem"&gt;' Load the order into a POCO&lt;/span&gt;
Next&lt;/pre&gt;

&lt;p&gt;In this case we fetch the firstCustomer once and reuse it rather than calling FirstOrDefault repeatedly. We also use the .Include option to eagerly fetch the child records. In this case, I’m saddened that the original developer didn’t use a bit of brain power to eliminate those extra database hits FOR LOGGING PURPOSES, but assume that it was because they weren’t aware of when their database was being hit. Of course, this brings us back to rule 2 – profiling.&lt;/p&gt;

&lt;p&gt;Simply removing excessive database hits will almost always improve your code performance. In one case, I had a situation where a request was taking 10 minutes. After removing the excessive hits, the performance came down to 10 seconds, which was a definite improvement. However, 10 seconds still does not make the application web scale as the database’s CPU is pegged for that amount of time. Sometimes, it is actually best to break the process up a bit to improve performance.&lt;/p&gt;

&lt;h4&gt;RULE 4: Break up complex queries&lt;/h4&gt;

&lt;p&gt;To give you an idea of the kind of query that we’re talking about here, consider the following case where we are fetching the employees in USA including their regions and sales information. &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; empOrders = 
    From e &lt;span class="kwrd"&gt;In&lt;/span&gt; Employees
    Where e.Country = &lt;span class="str"&gt;&amp;quot;USA&amp;quot;&lt;/span&gt;
    &lt;span class="kwrd"&gt;Select&lt;/span&gt; 
        e.FirstName,
        e.LastName,
        Regions = From t &lt;span class="kwrd"&gt;In&lt;/span&gt; e.Territories
                  &lt;span class="kwrd"&gt;Select&lt;/span&gt; t.Region.RegionDescription
                  Distinct,
        TopThreeSales = From o &lt;span class="kwrd"&gt;In&lt;/span&gt; e.Orders
                        From od &lt;span class="kwrd"&gt;In&lt;/span&gt; o.OrderDetails
                        &lt;span class="kwrd"&gt;Select&lt;/span&gt;
                            od.Product.ProductName,
                            TotalSale = od.Quantity * od.UnitPrice
                        Order By TotalSale Descending&lt;/pre&gt;

&lt;p&gt;While this code will compile and run, the performance will start to suffer as larger volumes of data are added to the database. The reason is that both Territories and Orders are child collections from Employees. As a result, SQL will return the Cartesian product between the two sets. In other words, if a single employee is associated with 5 territories and has sold 10 products, the total number of rows returned would be 50. The OR/M is then responsible for splitting out those results again into the correct groupings. If you multiply this against 10,000 employees, you will find that there is a massive amount of excess data that is returned.&lt;/p&gt;

&lt;p&gt;In this case, It may be helpful to split your sub queries up into separate database requests. You could do something like the following using the Contains clause to pass the Id’s of the parent record in to the subsequent&amp;#160; queries.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; empOnly = 
    (From e &lt;span class="kwrd"&gt;In&lt;/span&gt; Employees 
    Where e.Country = &lt;span class="str"&gt;&amp;quot;USA&amp;quot;&lt;/span&gt; 
    &lt;span class="kwrd"&gt;Select&lt;/span&gt; 
        e.EmployeeID, 
        e.FirstName, 
        e.LastName). 
    ToList()

&lt;span class="kwrd"&gt;Dim&lt;/span&gt; EmpIds = empOnly.&lt;span class="kwrd"&gt;Select&lt;/span&gt;(&lt;span class="kwrd"&gt;Function&lt;/span&gt;(e) e.EmployeeID)

&lt;span class="kwrd"&gt;Dim&lt;/span&gt; TopThreeSales = 
    From o &lt;span class="kwrd"&gt;In&lt;/span&gt; Orders
    Where EmpIds.Contains(o.EmployeeID)
    From od &lt;span class="kwrd"&gt;In&lt;/span&gt; o.OrderDetails
    &lt;span class="kwrd"&gt;Select&lt;/span&gt; 
        o.EmployeeID,
        od.Product.ProductName,
        TotalSale = od.Quantity * od.UnitPrice
    Order By TotalSale Descending&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;However “Contains” has a couple of hidden surprises that limit our use here. First if you use Contains, you can not make it into a compiled query because the number of parameters vary at run-time. Second, if you have more than 2100 items in your EmpIds collection, you will run into a &lt;a href="http://stackoverflow.com/questions/656167/hitting-the-2100-parameter-limit-sql-server-when-using-contains"&gt;hard limit in SQL Server which only allows up to 2100 parameters&lt;/a&gt;. In this event, it is better to re-apply the original filter and return the new result sets for each of the subsequent queries. In the end we can join the separate queries back together again using LINQ to Objects:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; empOnly = 
    (From e &lt;span class="kwrd"&gt;In&lt;/span&gt; Employees
    Where e.Country = &lt;span class="str"&gt;&amp;quot;USA&amp;quot;&lt;/span&gt;
    &lt;span class="kwrd"&gt;Select&lt;/span&gt; 
        e.EmployeeID,
        e.FirstName,
        e.LastName).
    ToList()

&lt;span class="kwrd"&gt;Dim&lt;/span&gt; Regions = 
    (From e &lt;span class="kwrd"&gt;In&lt;/span&gt; Employees 
    Where e.Country = &lt;span class="str"&gt;&amp;quot;USA&amp;quot;&lt;/span&gt;
    From t &lt;span class="kwrd"&gt;In&lt;/span&gt; e.Territories
    &lt;span class="kwrd"&gt;Select&lt;/span&gt; 
        e.EmployeeID,
        t.Region.RegionDescription
    Distinct).
    ToList()

&lt;span class="kwrd"&gt;Dim&lt;/span&gt; TopThreeSales = 
    (From e &lt;span class="kwrd"&gt;In&lt;/span&gt; Employees 
    Where e.Country = &lt;span class="str"&gt;&amp;quot;USA&amp;quot;&lt;/span&gt;
    From o &lt;span class="kwrd"&gt;In&lt;/span&gt; e.Orders
    From od &lt;span class="kwrd"&gt;In&lt;/span&gt; o.OrderDetails
    &lt;span class="kwrd"&gt;Select&lt;/span&gt; 
        o.EmployeeID,
        od.Product.ProductName,
        TotalSale = od.Quantity * od.UnitPrice
    Order By TotalSale Descending).
    ToList()
                
&lt;span class="kwrd"&gt;Dim&lt;/span&gt; combined = 
    From e &lt;span class="kwrd"&gt;In&lt;/span&gt; empOnly
    &lt;span class="kwrd"&gt;Select&lt;/span&gt; 
        e.FirstName,
        e.LastName,
        EmpRegions = Regions.Where(&lt;span class="kwrd"&gt;Function&lt;/span&gt;(reg) e.EmployeeID = reg.EmployeeID),
        Sales =  TopThreeSales.Where(&lt;span class="kwrd"&gt;Function&lt;/span&gt;(sale) e.EmployeeID = sale.EmployeeID)
    &lt;/pre&gt;

&lt;h4&gt;In the above referenced project, I was able to take some queries that as a single LINQ statement took 10 seconds to run on the database down to sub-second requests. Your mileage may vary using this technique. If at all unsure, refer back to Rule 2: Profile.&lt;/h4&gt;

&lt;h4&gt;RULE 5: Use ORM by default but Stored Proc where necessary&lt;/h4&gt;

&lt;p&gt;At times you will find that the generated query is too complex and the database has issues trying to parse the generated SQL. The complexity of your query, particularly the number of joins and depth of the object graph/inheritance model you are traversing can cause issues. In these cases, I have no objections to using Stored Procedures in order to wrangle the otherwise unruly queries. LINQ to DB is great for the 70-80% of crud operations, but there are times, particularly when reporting when you need something else. Thankfully LINQ to SQL and LINQ to EF both support consuming stored procedures when the need arises without the need to write the tedious and potentially error prone custom ADO code yourself.&lt;/p&gt;

&lt;p&gt;In addition, LINQ is not a replacement for ETL operations. In one case, we had a situation where saving a single record with 2000 children caused the database to churn for 10 minutes due to 2001 individual hits to the database for the update process (on a single SaveChanges call). We re-wrote that operation using BulkCopy and brought the operation down to 1 second from 10 minutes. &lt;/p&gt;

&lt;h4&gt;RULE 6: Use Appropriate Sample Data&lt;/h4&gt;

&lt;p&gt;The last item for today is to make sure when developing to have representative quantities of data in your sample as you will have after a couple of years of production data enters your system. We found a number of cases where complex queries like I described in rule 4 above would perform fine in development where we had thousands of rows of data, but when we applied it against the production data which had millions of rows of data, the performance died. The complex joins which worked fine against smaller data sets no longer worked against the bigger sets. If we had a good approximation of data volumes in development, we would have been able to diagnose and fix this issue before shipping the version to production.&lt;/p&gt;

&lt;p&gt;That’s just a couple of my rules of thumb which have helped me diagnose and fix performance issues with LINQ to SQL/EF. If you have any tricks or techniques to add, please let me know what you Thinq.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_6Vg2RQRkwo:Wiwnp9DF_Jo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_6Vg2RQRkwo:Wiwnp9DF_Jo:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_6Vg2RQRkwo:Wiwnp9DF_Jo:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=_6Vg2RQRkwo:Wiwnp9DF_Jo:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_6Vg2RQRkwo:Wiwnp9DF_Jo:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_6Vg2RQRkwo:Wiwnp9DF_Jo:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_6Vg2RQRkwo:Wiwnp9DF_Jo:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=_6Vg2RQRkwo:Wiwnp9DF_Jo:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=_6Vg2RQRkwo:Wiwnp9DF_Jo:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=_6Vg2RQRkwo:Wiwnp9DF_Jo:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/_6Vg2RQRkwo" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/1">LINQ</category> 
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 
                        <category domain="/Post.aspx/Category/10">Entity Framework</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/LINQ-to-Database-Performance-hints</feedburner:origLink></item>
                <item>
                      <title>Using Rx to consume a Task based WCF service</title>
                      <link>http://feedproxy.google.com/~r/thinqlinq/rss/~3/xoQb5FwoWzo/Using-Rx-to-consume-a-Task-based-WCF-service</link>
                      <pubDate>Tue, 22 May 2012 02:33:00 GMT</pubDate>
                      <guid isPermaLink="false">42f563c8-34ea-4d01-bfe1-2047c2222a74:22178</guid>
                      <dc:creator>Jim Wooley</dc:creator>
                      <slash:comments>0</slash:comments>
                      <comments>/Post.aspx/Title/Using-Rx-to-consume-a-Task-based-WCF-service</comments>
                      <wfw:commentRss>/Rss.aspx/Comment/22178</wfw:commentRss>
                      <wfw:comment>/Post.aspx/Title/Using-Rx-to-consume-a-Task-based-WCF-service</wfw:comment>
                      <description>&lt;p&gt;Among the many changes that Dev 11 brings is the new default when adding a service reference to generate Task based proxy methods rather than using the APM flavor (using the BeginXXX – EndXXX model). In this post, we’ll look at creating a simple service and then consuming it using the Reactive Extensions. Let’s start by defining the service interface and implementation:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.ServiceModel
&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Threading 

&amp;lt;ServiceContract()&amp;gt;
&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Interface&lt;/span&gt; ISimpleServicesvc

    &amp;lt;OperationContract()&amp;gt;
    &lt;span class="kwrd"&gt;Function&lt;/span&gt; DoSomethingCool(input &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;

&lt;span class="kwrd"&gt;End&lt;/span&gt; Interface

&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; SimpleServicesvc
    &lt;span class="kwrd"&gt;Implements&lt;/span&gt; ISimpleServicesvc

    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; DoSomethingCool(input &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt; &lt;span class="kwrd"&gt;Implements&lt;/span&gt; ISimpleServicesvc.DoSomethingCool
        &lt;span class="kwrd"&gt;Return&lt;/span&gt; (&lt;span class="kwrd"&gt;String&lt;/span&gt;.Join(&lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;, From letter &lt;span class="kwrd"&gt;In&lt;/span&gt; input.ToCharArray()
               Order By letter
               Distinct))
    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt;

&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Essentially here we are just taking a string input and returning the distinct characters sorted. The details of the service in this case are trivial. Our focus here is how to implement the service client. We start by adding a service reference in our client application by right clicking on the project and selecting Add Service Reference. (Alternatively, you can now press Ctrl-Q and request to “Add Service Reference” from there. From the dialog, you can still use the “Discover” button to locate the service as long as it is in your solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/8fb952c2ffe7_11C7F/image.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://www.thinqlinq.com/images/8fb952c2ffe7_11C7F/image_thumb.png" width="419" height="338" /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;One thing to note is that the proxy classes are now by default generated using Task based methods rather than the previous IAsyncResult AMP method.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.thinqlinq.com/images/8fb952c2ffe7_11C7F/image_3.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://www.thinqlinq.com/images/8fb952c2ffe7_11C7F/image_thumb_3.png" width="423" height="145" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a result, the definition of the proxy class is as follows:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; DoSomethingCoolAsync(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; input &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;) 
                 &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;font style="background-color: #ffff00"&gt;System.Threading.Tasks.Task(Of &lt;span class="kwrd"&gt;String&lt;/span&gt;)&lt;/font&gt; 
                 &lt;span class="kwrd"&gt;Implements&lt;/span&gt; SimpleService.ISimpleServicesvc.DoSomethingCoolAsync
    &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.Channel.DoSomethingCoolAsync(input)
&lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;

&lt;p&gt;If we wanted to consume this using the new Async/Await, we could do it as follows:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; Async &lt;span class="kwrd"&gt;Sub&lt;/span&gt; SubmitClicked() &lt;span class="kwrd"&gt;Handles&lt;/span&gt; SubmitButton.Click
   &lt;span class="kwrd"&gt;Dim&lt;/span&gt; svc = &lt;span class="kwrd"&gt;New&lt;/span&gt; SimpleService.SimpleServicesvcClient()
   &lt;span class="kwrd"&gt;Dim&lt;/span&gt; req = Await svc.DoSomethingCoolAsync(InputText.Text)
   OutputText.Text = req
&lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

&lt;p&gt;Of course, to put the LINQ spin on this, let’s see the Rx version to do the same thing:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; Async &lt;span class="kwrd"&gt;Sub&lt;/span&gt; SubmitClicked() &lt;span class="kwrd"&gt;Handles&lt;/span&gt; SubmitButton.Click
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; svc = &lt;span class="kwrd"&gt;New&lt;/span&gt; SimpleService.SimpleServicesvcClient()
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; req = svc.DoSomethingCoolAsync(InputText.Text).&lt;font style="background-color: #ffff00"&gt;ToObservable()
&lt;/font&gt;    req.ObserveOnDispatcher().Subscribe(&lt;span class="kwrd"&gt;Sub&lt;/span&gt;(val) OutputText.Text = val)
&lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

&lt;p&gt;&lt;font size="2" face="Consolas"&gt;We start by turning the Task into an Observable producer using the ToObservable extension method. We then subscribe to the observable making sure to return back to the dispatcher thread because the task based service is run on a taskpool thread. Of course in this case, we are subscribing on every button click. With Rx, we could wire the button click and service request up on form navigate and unwire it when navigating from the form as follows:&lt;/font&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Private&lt;/span&gt; requestDisposable &lt;span class="kwrd"&gt;As&lt;/span&gt; IDisposable
&lt;span class="kwrd"&gt;Protected&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; OnNavigatedTo(e &lt;span class="kwrd"&gt;As&lt;/span&gt; Navigation.NavigationEventArgs)
    &lt;span class="kwrd"&gt;Dim&lt;/span&gt; svc = &lt;span class="kwrd"&gt;New&lt;/span&gt; SimpleService.SimpleServicesvcClient

    requestDisposable = (From click &lt;span class="kwrd"&gt;In&lt;/span&gt; Observable.FromEventPattern(Of RoutedEventArgs)(SubmitButton, &lt;span class="str"&gt;&amp;quot;Click&amp;quot;&lt;/span&gt;)
                        From req &lt;span class="kwrd"&gt;In&lt;/span&gt; svc.DoSomethingCoolAsync(InputText.Text).ToObservable()
                        &lt;span class="kwrd"&gt;Select&lt;/span&gt; req).
                        ObserveOnDispatcher().
                        Subscribe(&lt;span class="kwrd"&gt;Sub&lt;/span&gt;(val) OutputText.Text = val)
&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;
&lt;span class="kwrd"&gt;Protected&lt;/span&gt; &lt;span class="kwrd"&gt;Overrides&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; OnNavigatedFrom(e &lt;span class="kwrd"&gt;As&lt;/span&gt; Navigation.NavigationEventArgs)
    &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.OnNavigatedFrom(e)
    requestDisposable.Dispose()
    requestDisposable = &lt;span class="kwrd"&gt;Nothing&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=xoQb5FwoWzo:7g3F1CRYzJU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=xoQb5FwoWzo:7g3F1CRYzJU:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=xoQb5FwoWzo:7g3F1CRYzJU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=xoQb5FwoWzo:7g3F1CRYzJU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=xoQb5FwoWzo:7g3F1CRYzJU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=xoQb5FwoWzo:7g3F1CRYzJU:dnMXMwOfBR0"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?d=dnMXMwOfBR0" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=xoQb5FwoWzo:7g3F1CRYzJU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=xoQb5FwoWzo:7g3F1CRYzJU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/thinqlinq/rss?a=xoQb5FwoWzo:7g3F1CRYzJU:KwTdNBX3Jqk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/thinqlinq/rss?i=xoQb5FwoWzo:7g3F1CRYzJU:KwTdNBX3Jqk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/thinqlinq/rss/~4/xoQb5FwoWzo" height="1" width="1"/&gt;</description>
                        <category domain="/Post.aspx/Category/20">WCF</category> 
                        <category domain="/Post.aspx/Category/24">Rx</category> 
                        <category domain="/Post.aspx/Category/9">VB Dev Center</category> 

                  <feedburner:origLink>http://www.Thinqlinq.com/Post.aspx/Title/Using-Rx-to-consume-a-Task-based-WCF-service</feedburner:origLink></item>

   </channel>
</rss>
