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

<channel>
	<title>.Net Smoothie &#187; ASP.Net</title>
	<atom:link href="http://www.richardbushnell.net/category/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.richardbushnell.net</link>
	<description></description>
	<lastBuildDate>Wed, 30 Dec 2009 11:42:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Learning Windows Azure</title>
		<link>http://www.richardbushnell.net/2009/03/12/learning-windows-azure/</link>
		<comments>http://www.richardbushnell.net/2009/03/12/learning-windows-azure/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 10:01:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Azure cloud getting-started]]></category>

		<guid isPermaLink="false">http://www.richardbushnell.net/index.php/2009/03/12/learning-windows-azure/</guid>
		<description><![CDATA[I started to learn how to use the Azure Cloud Service from Microsoft this week. Currently it&#8217;s still in Tech Preview stage. Unfortunately you can tell that from the SDK documentation. Here&#8217;s some useful links to get you going: Screencasts: http://msdn.microsoft.com/en-us/azure/dd439432.aspx These are quite basic, but trust me, you need them to be basic to [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2009%2F03%2F12%2Flearning-windows-azure%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>I started to learn how to use the Azure Cloud Service from Microsoft this week. Currently it&#8217;s still in Tech Preview stage. Unfortunately you can tell that from the SDK documentation.</p>
<p>Here&#8217;s some useful links to get you going:</p>
<ol>
<li><strong>Screencasts</strong>: <a title="http://msdn.microsoft.com/en-us/azure/dd439432.aspx" href="http://msdn.microsoft.com/en-us/azure/dd439432.aspx">http://msdn.microsoft.com/en-us/azure/dd439432.aspx</a>       <br />These are quite basic, but trust me, you need them to be basic to get you started. </li>
<li><strong>SDK</strong>: <a title="http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&amp;displaylang=en</a>       <br />Contains CHTM-style documentation, tools and samples. Don&#8217;t expect too much from the docs; they explain enough to get you confused, and then have an API reference. You need to unzip the samples and get into them to start understanding how everything fits together. </li>
<li><strong>Visual Studio Templates</strong>: <a title="http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&amp;displaylang=en</a>       <br />This gives you a set of project and item templates which you can use to create and publish Azure applications. Don&#8217;t worry about the extra projects it adds to a solution, or the config files. You will learn more about them later. </li>
<li>The <strong>Azure developer center</strong> on MSDN: <a title="http://msdn.microsoft.com/en-us/azure/default.aspx" href="http://msdn.microsoft.com/en-us/azure/default.aspx">http://msdn.microsoft.com/en-us/azure/default.aspx</a> </li>
</ol>
<p>Assuming you already <a href="http://go.microsoft.com/fwlink/?LinkID=129453" target="_blank">registered for Azure</a>, that&#8217;s all you really need to get started.</p>
<p>The biggest problem I found at first was deploying an app. Once you have generated an Azure project in Visual Studio, you expect to be able to publish it from Visual Studio too. Unfortunately you can&#8217;t, and it takes a little more effort. I&#8217;ll write more about that in another post.</p>
<p>I also needed help trying to understand what to focus on to get started. So here&#8217;s a big tip: Ignore .Net Services, Live Services, and SQL Data Services. They aren&#8217;t part of Azure per se. You can come back to them later. First you just need a hosted project and some storage &#8211; either blob storage or table storage. (There&#8217;s also queue storage, but I bet no one will want to use that straight away &#8211; it&#8217;s for tying two apps together, which no one will want to do at first.)</p>
<p>I recommend you <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&amp;displaylang=en">download the SDK</a> and the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&amp;displaylang=en">Visual Studio templates</a>, create yourself a &#8220;Web Role&#8221; project (which is really the equivalent of an ASP.Net project), and work on that. Then move onto table and blob storage. You can use the <a href="http://msdn.microsoft.com/en-us/azure/dd439432.aspx" target="_blank">screencasts</a> to help you.</p>
<p>Good luck getting started!</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2009%2F03%2F12%2Flearning-windows-azure%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2009/03/12/learning-windows-azure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Acrobatics : Lambdas and Expression Methods as a replacement for NVelocity</title>
		<link>http://www.richardbushnell.net/2008/06/02/c-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity/</link>
		<comments>http://www.richardbushnell.net/2008/06/02/c-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 10:09:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Lambda Expressions]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ListView]]></category>
		<category><![CDATA[NVelocity]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/06/02/c-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity/</guid>
		<description><![CDATA[I&#8217;ve been very quiet recently. (I&#8217;m trying to not be so loud, Scott. ) You see, I&#8217;ve been writing a lot of ASP.Net code for a site I&#8217;m working on. And, to be honest, I&#8217;ve been having a lot of trouble. The source code for .Net has been very helpful, and I&#8217;ve learnt a lot [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F06%2F02%2Fc-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>I&#8217;ve been very quiet recently. (I&#8217;m trying to not be so <a href="http://www.hanselman.com/blog/ProfessionalismProgrammingAndPunditryAndSuccessAsAMetric.aspx" target="_blank">loud</a>, Scott. <img src='http://www.richardbushnell.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) You see, I&#8217;ve been writing a lot of ASP.Net code for a site I&#8217;m working on. And, to be honest, I&#8217;ve been having a <em>lot</em> of trouble. The <a href="http://richardbushnell.net/index.php/2008/04/18/the-value-of-being-free-to-see-the-source/" target="_blank">source code for .Net</a> has been very helpful, and I&#8217;ve learnt a lot about what&#8217;s going on under the covers of ASP.Net because of it. </p>
<p>(Note: I won&#8217;t comment here on the quality of the code I&#8217;ve found &#8211; I&#8217;ll leave that up to you to judge. But in any case, I&#8217;ve been trying to build on top of it.)</p>
<p>One thing I&#8217;ve found to be important is the reliance on Web Controls. (It&#8217;s got something to do with javascript libraries, but that&#8217;s another story.) Getting away from the &quot;standard&quot; way to do ASP.Net isn&#8217;t easy though. Even the ninjas on the <a href="http://www.haacked.com/archive/2008/05/31/the-design-is-never-right-the-first-time.aspx" target="_blank">ASP.Net MVC</a> team <a href="http://www.haacked.com/archive/2008/05/03/code-based-repeater-for-asp.net-mvc.aspx" target="_blank">seem to be having trouble</a>. However, with the magic of lambdas and extension methods in C#, I think I might have just about managed to get something usable. I thought I&#8217;d publish my work here, and see what comments I got.</p>
<p>I think it&#8217;s best to start with what my ASP.Net code looks like once I&#8217;ve got everything working. (Notice I still have some Web Controls in there, but that&#8217;s because I&#8217;ve not worked out how to do sorting of data without web controls yet.)</p>
<p>The inspiration for this was taken from the <a href="r" target="_blank">improvements made to NVelocity</a> by the gurus on the Castle Project. I thought it looked great, and I&#8217;d like something similar, but I didn&#8217;t really want to learn a whole new scripting language and integrate it into my working environment just for rendering a bit of HTML. So I built some C# classes to do a similar thing for me instead. It&#8217;s not as nice as NVelocity, but it&#8217;s okay for now.</p>
<p><strong>Warning</strong>: The following code may contain statements of a disturbing nature to more sensitive readers. We cannot be held responsible for any confusion, delusion or mental illness caused by this code.</p>
<p>It starts by taking a collection of Task objects, and calling the extension method &quot;ForEach&quot; on them:</p>
<pre class="code"><span style="background: #ffee62">&lt;%</span> Tasks.ForEach(sections =&gt; {
   sections.NoData = tasks =&gt; {
<span style="background: #ffee62">%&gt;
</span><span style="color: blue">   &lt;</span><span style="color: #a31515">p</span><span style="color: blue">&gt;
</span>   Hey, you've got nothing to do.<span style="color: blue">&lt;/</span><span style="color: #a31515">p</span><span style="color: blue">&gt;
   &lt;</span><span style="color: #a31515">p</span><span style="color: blue">&gt;
</span><span style="background: #ffee62">&lt;%
</span>   };
   sections.BeforeAll = tasks =&gt; {
   <span style="background: #ffee62">%&gt;
</span>  <span style="color: blue">&lt;</span><span style="color: #a31515">table </span><span style="color: red">class</span><span style="color: blue">=&quot;task-list&quot;&gt;
    &lt;</span><span style="color: #a31515">tr </span><span style="color: red">class</span><span style="color: blue">=&quot;task-list-header&quot;&gt;
      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">LinkButton </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Sort&quot; </span><span style="color: red">CommandArgument</span><span style="color: blue">=&quot;StartDate&quot;
          </span><span style="color: red">Text</span><span style="color: blue">=&quot;Started&quot; /&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">LinkButton </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Sort&quot; </span><span style="color: red">CommandArgument</span><span style="color: blue">=&quot;DueOn&quot;
          </span><span style="color: red">Text</span><span style="color: blue">=&quot;Due&quot; /&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">LinkButton </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Sort&quot; </span><span style="color: red">CommandArgument</span><span style="color: blue">=&quot;Priority&quot;
          </span><span style="color: red">Text</span><span style="color: blue">=&quot;Priority&quot; /&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">LinkButton </span><span style="color: red">CssClass</span><span style="color: blue">=&quot;task-description&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Sort&quot; </span><span style="color: red">CommandArgument</span><span style="color: blue">=&quot;Title&quot;
          </span><span style="color: red">Text</span><span style="color: blue">=&quot;Description&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; /&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;</span><span style="color: blue">      &lt;</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
      &lt;/</span><span style="color: #a31515">th</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">tr</span><span style="color: blue">&gt;
   </span><span style="background: #ffee62">&lt;%
</span>   };
     sections.Before = task =&gt; {
    <span style="background: #ffee62">%&gt;
</span>    <span style="color: blue">&lt;</span><span style="color: #a31515">tr </span><span style="color: red">class</span><span style="color: blue">=&quot;</span><span style="background: #ffee62">&lt;%</span>= this.tableCssClasses.Next() <span style="background: #ffee62">%&gt;</span><span style="color: blue">&quot;&gt;
    </span><span style="background: #ffee62">&lt;%
</span>   };
   sections.Each = task =&gt; {
    <span style="background: #ffee62">%&gt;</span>
    <span style="color: blue">&lt;</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">div </span><span style="color: red">class</span><span style="color: blue">='calendar calendar-icon-</span><span style="background: #ffee62">&lt;%</span>= task.StartMonth <span style="background: #ffee62">%&gt;</span><span style="color: blue">'&gt;
        &lt;</span><span style="color: #a31515">div </span><span style="color: red">class</span><span style="color: blue">=&quot;calendar-day&quot;&gt;
          </span><span style="background: #ffee62">&lt;%</span><span style="color: blue">= </span>task.StartDayOfMonth <span style="background: #ffee62">%&gt;</span><span style="color: blue">&lt;/</span><span style="color: #a31515">div</span><span style="color: blue">&gt;
      &lt;/</span><span style="color: #a31515">div</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">div </span><span style="color: red">class</span><span style="color: blue">='calendar calendar-icon-</span><span style="background: #ffee62">&lt;%</span>= task.DueMonth <span style="background: #ffee62">%&gt;</span><span style="color: blue">'&gt;
        &lt;</span><span style="color: #a31515">div </span><span style="color: red">class</span><span style="color: blue">=&quot;calendar-day&quot;&gt;
          </span><span style="background: #ffee62">&lt;%</span><span style="color: blue">= </span>task.DueDayOfMonth <span style="background: #ffee62">%&gt;</span><span style="color: blue">&lt;/</span><span style="color: #a31515">div</span><span style="color: blue">&gt;
      &lt;/</span><span style="color: #a31515">div</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
      </span><span style="background: #ffee62">&lt;%</span><span style="color: blue">= </span>task.Priority <span style="background: #ffee62">%&gt;
</span>    <span style="color: blue">&lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">td </span><span style="color: red">class</span><span style="color: blue">=&quot;task-title&quot;&gt;
      &lt;</span><span style="color: #a31515">a </span><span style="color: red">href</span><span style="color: blue">='</span><span style="background: #ffee62">&lt;%</span>= Href.For(&quot;~/Tasks/{0}/Show.aspx&quot;, task.ID) <span style="background: #ffee62">%&gt;</span><span style="color: blue">'&gt;</span><span style="background: #ffee62">&lt;%</span><span style="color: blue">= </span>task.Title <span style="background: #ffee62">%&gt;</span><span style="color: blue">&lt;/</span><span style="color: #a31515">a</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
</span><span style="color: blue">    &lt;</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Button </span><span style="color: red">ID</span><span style="color: blue">=&quot;Button1&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CssClass</span><span style="color: blue">=&quot;button&quot; </span><span style="color: red">CommandName</span><span style="color: blue">=&quot;Delete&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Mark Done&quot; /&gt;
    &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
    </span><span style="background: #ffee62">&lt;%
</span>   };

   sections.After = task =&gt; {
    <span style="background: #ffee62">%&gt;
</span>    <span style="color: blue">&lt;/</span><span style="color: #a31515">tr</span><span style="color: blue">&gt;
    </span><span style="background: #ffee62">&lt;%
</span>   };

   sections.AfterAll = task =&gt; {
    <span style="background: #ffee62">%&gt;
</span>    <span style="color: blue">&lt;/</span><span style="color: #a31515">table</span><span style="color: blue">&gt;
    </span><span style="background: #ffee62">&lt;%
</span>   };
 });
<span style="background: #ffee62">%&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>It might take a while to grasp what&#8217;s going on here. The code actually starts using an Extension method to IEnumerable that looks like this:</p>
<pre class="code"><span style="color: gray">public static void </span>ForEach&lt;T&gt;(<span style="color: gray">this </span><span style="color: #2b91af">IEnumerable</span>&lt;T&gt; enumerable, <span style="color: #2b91af">ForeachSectionSetter</span>&lt;T&gt; sectionSetter) {
  <span style="color: gray">if </span>(enumerable != <span style="color: gray">null</span>) {

    <span style="color: gray">if </span>(sectionSetter != <span style="color: gray">null</span>) {
      <span style="color: #2b91af">ForeachSections</span>&lt;T&gt; sections = <span style="color: gray">new </span><span style="color: #2b91af">ForeachSections</span>&lt;T&gt;();
      sectionSetter(sections);

      <span style="color: gray">if </span>(enumerable.Count() == 0) {
        <span style="color: gray">if </span>(sections.NoData != <span style="color: gray">null</span>)
          sections.NoData(enumerable);
        <span style="color: gray">return</span>;
      }

      <span style="color: gray">if </span>(sections.BeforeAll != <span style="color: gray">null</span>)
        sections.BeforeAll(enumerable);

      <span style="color: gray">int </span>itemIndex = 0;
      T previousItem = <span style="color: gray">default</span>(T);

      <span style="color: gray">foreach </span>(T item <span style="color: gray">in </span>enumerable) {
        <span style="color: gray">if </span>(sections.Before != <span style="color: gray">null</span>)
          sections.Before(item);
        <span style="color: gray">if </span>(itemIndex % 2 == 1 &amp;&amp; sections.Odd != <span style="color: gray">null</span>)
          sections.Odd(item);
        <span style="color: gray">if </span>(itemIndex % 2 == 0 &amp;&amp; sections.Even != <span style="color: gray">null</span>)
          sections.Even(item);
        <span style="color: gray">if </span>(itemIndex &gt; 0 &amp;&amp; sections.Between != <span style="color: gray">null</span>)
          sections.Between(previousItem, item);
        <span style="color: gray">if </span>(sections.Each != <span style="color: gray">null</span>)
          sections.Each(item);
        <span style="color: gray">if </span>(sections.After != <span style="color: gray">null</span>)
          sections.After(item);
        itemIndex++;
        previousItem = item;
      }
      <span style="color: gray">if </span>(sections.AfterAll != <span style="color: gray">null</span>)
        sections.AfterAll(enumerable);
    }
  }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The delegate ForEachSectionSetter is used by the calling method with a lambda expression. As a parameter it receives an ForeachSections object, which looks like this:</p>
<pre class="code"><span style="color: gray">public class </span><span style="color: #2b91af">ForeachSections</span>&lt;T&gt; {
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; Each { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;<span style="color: #2b91af">IEnumerable</span>&lt;T&gt;&gt; BeforeAll { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; Before { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T,T&gt; Between { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; Odd { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; Even { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;T&gt; After { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;<span style="color: #2b91af">IEnumerable</span>&lt;T&gt;&gt; AfterAll { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
  <span style="color: gray">public </span><span style="color: #2b91af">Action</span>&lt;<span style="color: #2b91af">IEnumerable</span>&lt;T&gt;&gt; NoData { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The calling method gets the chance to set the properties of this class before it is returned to the constructor of the ForEach method for processing. And because each property is already preset to a default value (Null in this case), the constructor can use the ForeachSections object just like a set of default or optional parameters. The caller can simply set values to the properties it needs, and ignore the rest.</p>
<p>If I had tried this another way, using overloadable constructors, it would have led to multiple constructors with indistinguishable signatures. If I&#8217;d have used property initializers, I wouldn&#8217;t have been able to run the whole routine without requiring a second call to the object, which actually wasn&#8217;t possible. </p>
<p>Basically, I couldn&#8217;t think of another way to do it. </p>
<p>The properties of the ForeachSections object are all delegates too. That means that we can use them with lambdas, which gives us lambdas inside of a lambda. (Hmm, very confusing!)</p>
<p>So what do you think? Could <em>you</em> use something like this? Can you make it simpler? Leave me a comment if you can.</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F06%2F02%2Fc-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/06/02/c-acrobatics-lambdas-and-expression-methods-as-a-replacement-for-nvelocity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Value of Being Free to See the Source</title>
		<link>http://www.richardbushnell.net/2008/04/18/the-value-of-being-free-to-see-the-source/</link>
		<comments>http://www.richardbushnell.net/2008/04/18/the-value-of-being-free-to-see-the-source/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 14:09:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[exceptions]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/04/18/the-value-of-being-free-to-see-the-source/</guid>
		<description><![CDATA[Since the source code to ASP.Net was made available, I&#8217;ve been using it extensively. Here&#8217;s a great example of why it&#8217;s so valuable. I&#8217;ve been trying to integrate the Enterprise Library 3.1 Exception Handling Block into my application. My application is split into a core and web UI specific components, so I&#8217;ve defined errors in [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F04%2F18%2Fthe-value-of-being-free-to-see-the-source%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>Since the <a href="http://richardbushnell.net/index.php/2008/01/17/net-source-code-now-available/">source code to ASP.Net was made available</a>, I&#8217;ve been using it extensively. Here&#8217;s a great example of why it&#8217;s so valuable.</p>
<p>I&#8217;ve been trying to integrate the Enterprise Library 3.1 Exception Handling Block into my application. My application is split into a core and web UI specific components, so I&#8217;ve defined errors in my code to be thrown when a resource is not available. The web application configuration file specifies that if a specific exception, e.g. a ResourceNotFoundException, is thrown, the Exception Handling Block should replace that exception with a 404 Resource Not Found error using Http. That should in turn use the CustomErrors feature to redirect to a 404 not found page.</p>
<p>Makes sense, and sounds simple, don&#8217;t you think? </p>
<p>Nothing in the docs says that it shouldn&#8217;t work.</p>
<p><em>But it doesn&#8217;t</em>. It simply <em>won&#8217;t work</em>. Why? Well, there&#8217;s nothing on the web. But after spending some serious hours digging through the source code, I can finally see why.</p>
<p>Here&#8217;s a lovely little hidden-to-the-world snippet of the code I got inside of Visual Studio:</p>
<pre class="code">code = HttpException.GetHttpCodeForException(e);

<span style="color: green">// Don't raise event for 404.  See VSWhidbey 124147.
</span><span style="color: blue">if </span>(code != 404) {
  WebBaseEvent.RaiseRuntimeError(e, <span style="color: blue">this</span>);
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>So it would never work! </p>
<p>Nice of them to let me know.</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F04%2F18%2Fthe-value-of-being-free-to-see-the-source%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/04/18/the-value-of-being-free-to-see-the-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mix 08 Online Presentations</title>
		<link>http://www.richardbushnell.net/2008/03/04/mix-08-online-presentations/</link>
		<comments>http://www.richardbushnell.net/2008/03/04/mix-08-online-presentations/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 06:06:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Mix08]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/04/mix-08-online-presentations/</guid>
		<description><![CDATA[My favorite conference is about to start: MIX 08. It&#8217;s a great conference for Microsoft developers with an interest in the web. Last year they had some great talks about user experience and architecture. There&#8217;s always something interesting to learn. Unfortunately I can&#8217;t be there (as usual), but all the sessions will be online. Tim [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F03%2F04%2Fmix-08-online-presentations%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>My favorite conference is about to start: MIX 08. </p>
<p>It&#8217;s a great conference for Microsoft developers with an interest in the web. Last year they had some great talks about user experience and architecture. There&#8217;s always something interesting to learn.</p>
<p>Unfortunately I can&#8217;t be there (as usual), but all the sessions will be online. Tim Sneath just posted <a href="http://blogs.msdn.com/tims/archive/2008/03/03/mix08-for-non-attendees.as" target="_blank">details of where and when you can watch them:</a></p>
<ul>
<li>The keynote with Ray Ozzie, Scott Guthrie will be available <em>live</em> at 9:30am Pacific / 5:30pm GMT on three streams: <a href="http://wm.istreamplanet.com/customers/ms/750_microsoft_mix_080305.asx">750kbps</a>, <a href="http://wm.istreamplanet.com/customers/ms/300_microsoft_mix_080305.asx">300kbps</a>, <a href="http://wm.istreamplanet.com/customers/ms/100_microsoft_mix_080305.asx">100kbps</a>. </li>
<li>The breakout sessions and panels will be online within 24 hours of each session at <a href="http://sessions.visitmix.com/">MIX08 sessions</a>.</li>
</ul>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F03%2F04%2Fmix-08-online-presentations%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/03/04/mix-08-online-presentations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://wm.istreamplanet.com/customers/ms/750_microsoft_mix_080305.asx" length="566" type="video/x-ms-asf" />
<enclosure url="http://wm.istreamplanet.com/customers/ms/300_microsoft_mix_080305.asx" length="566" type="video/x-ms-asf" />
<enclosure url="http://wm.istreamplanet.com/customers/ms/100_microsoft_mix_080305.asx" length="566" type="video/x-ms-asf" />
		</item>
		<item>
		<title>A Pure ASP.Net Grid with Grouping</title>
		<link>http://www.richardbushnell.net/2008/03/02/a-pure-aspnet-grid-with-grouping/</link>
		<comments>http://www.richardbushnell.net/2008/03/02/a-pure-aspnet-grid-with-grouping/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 19:26:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Grouping]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[LinqDataSource]]></category>
		<category><![CDATA[ListView]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/03/02/a-pure-aspnet-grid-with-grouping/</guid>
		<description><![CDATA[One of my favorite bloggers is Matt Berseth. Nearly once a week he comes up with a post where he does something amazing with the standard ASP.Net controls. I usually read his posts in awe. He&#8217;s really good. But he&#8217;s not only is a good developer, he&#8217;s a great writer. Even though his posts are [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F03%2F02%2Fa-pure-aspnet-grid-with-grouping%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>One of my favorite bloggers is <a href="http://mattberseth.com/blog">Matt Berseth</a>. Nearly once a week he comes up with a post where he does something amazing with the standard ASP.Net controls. I usually read his posts in awe. He&#8217;s really good.</p>
<p>But he&#8217;s not only is a good developer, he&#8217;s a great writer. Even though his posts are concise and straight to the point, most of them are pages long. You can really learn a lot from following his instructions.</p>
<p>He&#8217;s so good, in fact, that he regularly gets a mention on Scott Guthrie&#8217;s posts.</p>
<p>One of my favorite posts of his was where he used LINQ-to-SQL, a LinqDataSource control, and an ASP.Net ListView control &#8211; all new in .Net 3.5 &#8211; and made a grid with grouping functionality. He did it all in a standard way, and didn&#8217;t use any funny tricks.</p>
<p><a href="http://mattberseth.com/blog/2008/01/building_a_grouping_grid_with.html"><img style="border-right: 0px; border-top: 0px; margin: 0px; border-left: 0px; border-bottom: 0px" height="350" alt="image" src="http://www.richardbushnell.net/wp-content/uploads/2008/03/image1.png" width="465" border="0" /></a> </p>
<p>Here&#8217;s a link to the article:</p>
<h5><a href="http://mattberseth.com/blog/2008/01/building_a_grouping_grid_with.html">Building a Grouping Grid with the ASP.NET 3.5 LinqDataSource and ListView Controls</a></h5>
<p>Enjoy!</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F03%2F02%2Fa-pure-aspnet-grid-with-grouping%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/03/02/a-pure-aspnet-grid-with-grouping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Start Learning Silverlight 2.0 Now</title>
		<link>http://www.richardbushnell.net/2008/02/22/start-learning-silverlight-20-now/</link>
		<comments>http://www.richardbushnell.net/2008/02/22/start-learning-silverlight-20-now/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 18:13:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 2.0]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/22/start-learning-silverlight-20-now/</guid>
		<description><![CDATA[Now this is exciting. (Well, if you&#8217;re a geek.) Silverlight 2.0 is on its way, and Scott Guthrie has posted 8 tutorials about using it. I&#8217;m off to read them now&#8230;]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F02%2F22%2Fstart-learning-silverlight-20-now%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>Now <a href="http://weblogs.asp.net/scottgu/archive/2008/02/22/first-look-at-silverlight-2.aspx" target="_blank">this</a> is exciting. (Well, if you&#8217;re a geek.)</p>
<p>Silverlight 2.0 is on its way, and Scott Guthrie has posted <a href="http://weblogs.asp.net/scottgu/archive/2008/02/22/first-look-at-silverlight-2.aspx" target="_blank">8 tutorials</a> about using it.</p>
<p>I&#8217;m off to read them now&#8230;</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F02%2F22%2Fstart-learning-silverlight-20-now%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/02/22/start-learning-silverlight-20-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The LinqDataSource and the Hidden Viewstate</title>
		<link>http://www.richardbushnell.net/2008/02/21/the-linqdatasource-and-the-hidden-viewstate/</link>
		<comments>http://www.richardbushnell.net/2008/02/21/the-linqdatasource-and-the-hidden-viewstate/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 08:00:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quaility]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[LinqDataSource]]></category>
		<category><![CDATA[ViewState]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/21/the-linqdatasource-and-the-hidden-viewstate/</guid>
		<description><![CDATA[Yesterday I thought I&#8217;d learn about the LinqDataSource in ASP.Net 3.5, and got an interesting surprise. The new LinqDataSource can also be used with a LINQ-to-SQL model to perform updates. You simply add the DataSource to your page, set the table name, and set EnableUpdate to true. Then, using a standard DataControl, you can make [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F02%2F21%2Fthe-linqdatasource-and-the-hidden-viewstate%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>Yesterday I thought I&#8217;d learn about the <strong>LinqDataSource</strong> in ASP.Net 3.5, and got an interesting surprise.</p>
<p>The new <strong>LinqDataSource</strong> can also be used with a LINQ-to-SQL model to perform updates. You simply add the <strong>DataSource</strong> to your page, set the table name, and set <strong>EnableUpdate</strong> to true. Then, using a standard <strong>DataControl</strong>, you can make updates to your data entities.</p>
<p>The question is, how does this work? It appears to be a bit magical. <span id="more-55"></span></p>
<h2>The Magic of LINQ</h2>
<p>In a <a href="http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/">previous post</a>, I mentioned that LINQ-to-SQL updates can be done in two ways: either you make a call to retrieve a row, then update it, or you provide known values for all fields and try to update using optimistic concurrency.</p>
<p>If the <strong>LinqDataSource</strong> used the first technique, the performance might be bad. Plus, it would have to only update those fields that had been updated by the <strong>DataControl</strong>, and ignore the rest. That wouldn&#8217;t make sense, so I correctly supposed that was not what was happening.</p>
<p>It makes more sense that the <strong>LinqDataSource</strong> would use the values input by the user to make the changes. It could use optimistic concurrency to compare all the entered values.</p>
<p>The problem is, I don&#8217;t always display all fields from a particular row on the form, so how would the <strong>LinqDataSource</strong> know what the missing fields were. Remember, all the fields involved in the update are required for the optimistic concurrency to work. That is usually all the fields in a row, and they aren&#8217;t usually all displayed.</p>
<p>So, have a guess. Where does the <strong>LinqDataSource</strong> store it&#8217;s values?</p>
<p>Let&#8217;s think now. Where would be the <em>easiest </em>place to keep it? To keep it really simple, I&#8217;ll let you ignore <a href="http://richardbushnell.net/index.php/2007/12/23/qualities-of-a-dot-net-application-design/">all other aspects of building an application</a>, like security or performance.</p>
<p>Yep, you guessed it &#8211; <strong>ViewState</strong>.</p>
<p>The ViewState actually contains all values for all the fields in a LINQ-to-SQL entity by default. Those values are sent to the client, even if the user isn&#8217;t supposed to be able to see them.</p>
<p>Aaaarrgghhhh!</p>
<p>Now, let&#8217;s not get overexcited. The ViewState is encoded, so it&#8217;s not easy to just go and change it. But it&#8217;s not impossible. In general, I don&#8217;t think it&#8217;s such a great idea to have all data sent to a client by default. Someone is going to overlook something one day, and there&#8217;ll be a costly mistake.</p>
<p>And what if you display a large grid using the LinqDataSource. Well, you aren&#8217;t just getting the ViewState from the grid sent back and forth with your page, but the LinqDataSource is going to store <em>all your data</em> retrieved in the ViewState too.</p>
<p>Bummer!</p>
<p>Great control. Large overhead.</p>
<h2>Kicking out the ViewState</h2>
<p>The good news is that the ASP.Net team realized that this was a problem and did something about it.</p>
<p>If you look carefully, you will notice that the <strong>LinqDataSource</strong> has a property <strong>StoreOriginalValuesInViewState</strong>. By default (sigh) that property is set to true. If you set it to false, the control won&#8217;t work any more. Simple as that.</p>
<p>Here&#8217;s what the official documentation has to say about that:</p>
<blockquote><p>If you set the <strong>StoreOriginalValuesInViewState</strong> property to false, the original values are not persisted in view state for the data-bound control. In that case, LINQ to SQL cannot verify the integrity of the data. LINQ to SQL will throw an exception that indicates a data conflict even if the data in the data source has not actually changed.</p></blockquote>
<p>That&#8217;s in the remarks section of the <strong>LinqDataSource</strong>.<strong>StoreOriginalValuesInViewState</strong> property documentation.</p>
<p>Funnily enough, the same section states the problem with stuffing data into the ViewState:</p>
<blockquote><p>Storing the original values in view state can cause the page size to become unnecessarily large and can expose sensitive data to a malicious user.</p></blockquote>
<p>Now, I don&#8217;t know about you, but that looks like a pretty serious warning to me. Why isn&#8217;t it in a more obvious place, like as a comment that pops in up Intellisense whenever you use a LinqDataSource?</p>
<h2>Check the UpdateCheck</h2>
<p>So how do you handle it? How can you use the <strong>LinqDataSource</strong>?</p>
<p>The answer lies in the generation of the LINQ-to-SQL model which you generate. Each entity field has a <strong>Column </strong>attribute which allows you to specify if it is used for checking during an optimistic concurrency field comparison.</p>
<p>For example, you could create a Model with the following Property:</p>
<pre class="code">[<span style="color: #2b91af">Column</span>(Storage=<span style="color: #a31515">"_AddressID"</span>, UpdateCheck=<span style="color: #2b91af">UpdateCheck</span>.Never, ...
<span style="color: blue">public int </span>AddressID
...</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Notice the <strong>UpdateCheck.Never </strong>value. That means that the field will not be used in the optimistic concurrency check.</p>
<p>The documentation helps a little again:</p>
<blockquote><p>By default, when update and delete operations have been enabled, the <a href="ms-help://ms.vscc.v90/9b2f476d-7f28-2aa8-8143-3082edcf11d5.htm">LinqDataSource</a> control stores the original values for all the records in view state. The <a href="ms-help://ms.vscc.v90/9b2f476d-7f28-2aa8-8143-3082edcf11d5.htm">LinqDataSource</a> control stores values for all primary keys and all properties not marked with UpdateCheck.Never in the Column attribute. You set the UpdateCheck property of the Column attribute in the O/R Designer.</p></blockquote>
<p>Admittedly, I haven&#8217;t yet tried that, so I don&#8217;t really know how if you can change that setting for a field without changing generated code, which would be a big no-no. I&#8217;ll just have to get back to you on that.</p>
<h2>Stamp In, Please</h2>
<p>However, there is a shortcut trick.</p>
<p>Basically, if you add a field of type <strong>timestamp</strong> to your record, only that field will be used for the concurrency check, and only that field&#8217;s data will be stored in the ViewState.</p>
<blockquote><p>If the underlying data source contains a timestamp field that is automatically updated during an update, you can store only that value in view state. In that case, the timestamp property in the entity class is set to IsVersion=true and all the properties are set to UpdateCheck.Never. Because a timestamp field is automatically updated by the database every time that data in that record changes, LINQ to SQL determines from that value if data has changed. This helps reduce the size of view state, and no sensitive data is exposed. LINQ to SQL will check for data consistency by comparing the timestamp value in view state with the timestamp value in the database.</p></blockquote>
<p>The documentation is great, if you know where to find it. <img src='http://www.richardbushnell.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Conclusion</h2>
<p>So, the answer is, if you use the <strong>LinqDataSource</strong> to throw a quick application together, make sure you use a <strong>timestamp</strong> field in your table. Call it <strong>UpdatedOn</strong>, or something. It will make the use of the <strong>LinqDataSource</strong> a lot easier, if only because you&#8217;ll sleep better not worrying about it.</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F02%2F21%2Fthe-linqdatasource-and-the-hidden-viewstate%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/02/21/the-linqdatasource-and-the-hidden-viewstate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My own ASP.Net MVP Framework</title>
		<link>http://www.richardbushnell.net/2008/02/03/my-own-aspnet-mvp-framework/</link>
		<comments>http://www.richardbushnell.net/2008/02/03/my-own-aspnet-mvp-framework/#comments</comments>
		<pubDate>Sun, 03 Feb 2008 13:59:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/03/my-own-aspnet-mvp-framework/</guid>
		<description><![CDATA[So, I did it! I finally did it! I wanted to publish my ideas for a framework, and I did. You can find it on CodePlex at http://www.codeplex.com/aspnetmvp. Go have a look. I really want to know what you think. Now, I know there are a million and one frameworks for the web, so I [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F02%2F03%2Fmy-own-aspnet-mvp-framework%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>So, I did it! I finally did it!</p>
<p>I wanted to publish my ideas for a framework, and I did. You can find it on CodePlex at <a href="http://www.codeplex.com/aspnetmvp">http://www.codeplex.com/aspnetmvp</a>.</p>
<p>Go have a look. I really want to know what you think.</p>
<p><span id="more-44"></span></p>
<p>Now, I know there are a million and one frameworks for the web, so I don&#8217;t intend on trying to make anything  big out of this. But I also know that my customers, usually decent developers with basic ASP.Net knowledge, are constantly asking me for guidance for creating ASP.Net projects. To avoid repeating myself over and over, this project gives them a good starting point. When something better comes along, I can point them to that instead.</p>
<p>I can also use the project as a place for creating new ideas, like</p>
<ul>
<li>WF integration and reusable workflows, like shopping carts or the &#8220;hub and spoke UI pattern&#8221;.</li>
<li>plug-ins and skins, like Dotnetnuke</li>
</ul>
<p>I definitely do not want to reinvent the wheel. But I believe that there are currently loads of great ideas which could be used in a framework, but just require a little bit of effort to make them simple to use (e.g. UrlRewriting). Most of the developers I know want those extra features without having to spend a lot of time learning a new technology. This framework should be for them.</p>
<p>Instead of totally turning the heads of such developers around, asking them to use a completely new system (e.g. the ASP.Net MVC framework), this framework is meant to provide helpful stuff without stopping you from doing things the way you want (favicons and robots.txt files, for example). It gives you guidance on where to put your CSS files, master pages, scripts, and images. It also provides a way to do testing and project management in a sensible and flexible way. It uses the MVP pattern, but that isn&#8217;t mandatory. You can still write code in webforms if you really want to, and then you can refactor them out quite easily later.</p>
<p>I based my MVP implementation on some of the code from the Microsoft Patterns and Practices Web Client Software Factory. However, they made extensive use of the ObjectBuilder and attributes, which I found to be overengineering and too complex. So, as an alternative, I recreated the ideas using generics. I found it works well, and doesn&#8217;t have the performance overhead or the learning curve required with WCS.</p>
<p>The code currently uses the AdventureWorks Database, which you will need to install first before using the code. You can find the database on CodePlex here.</p>
<p>I&#8217;m currently working on another top-secret project, so I won&#8217;t really be spending much time on this. If you&#8217;re interested in discussing ideas or doing something with the project, let me know. I&#8217;d love to hear what you have to offer.</p>
<p>Otherwise, head on over to the <a href="http://www.codeplex.com/aspnetmvp">ASP.Net MVP Framework site</a>, and check out the code.</p>
<p>Oh, and until the lawyers call and ask me to change the name, let&#8217;s just leave it as it is.</p>
<p>P.S. I forgot to mention a &#8220;feature&#8221;. The Yahoo UI Framework has some great stuff for CSS, including grid layouts and css reset files. I integrated that too. I put it in the default theme. It means you don&#8217;t have to do much work to get your stylesheets to lay out your webpages well.</p>
<p>More to come on that later.</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F02%2F03%2Fmy-own-aspnet-mvp-framework%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/02/03/my-own-aspnet-mvp-framework/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>ASP.Net MVC Corollary &#8211; What to do?</title>
		<link>http://www.richardbushnell.net/2008/01/28/aspnet-mvc-corollary-what-to-do/</link>
		<comments>http://www.richardbushnell.net/2008/01/28/aspnet-mvc-corollary-what-to-do/#comments</comments>
		<pubDate>Mon, 28 Jan 2008 03:50:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[SubSonic]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/01/28/aspnet-mvc-corollary-what-to-do/</guid>
		<description><![CDATA[Dude! I got quoted! And by none other than Rob Conery of SubSonic fame. It seems like my last post caused quite an unexpected stir. Thanks to both Rob and Scott for taking the time to answer me. I really appreciate it. A Word of Appreciation Let&#8217;s get something in perspective. Rob has actually produced [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F01%2F28%2Faspnet-mvc-corollary-what-to-do%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>Dude! I got <a href="http://blog.wekeroad.com/2008/01/25/ramble-aspnet-mvc-is-a-geek-chisel/" target="_blank">quoted</a>! And by none other than Rob Conery of SubSonic fame.</p>
<p>It seems like my <a href="http://richardbushnell.net/index.php/2008/01/25/does-the-aspnet-mvc-framework-frustrate-you/" target="_blank">last post</a> caused quite an unexpected stir. Thanks to both <a href="http://blog.wekeroad.com/2008/01/25/ramble-aspnet-mvc-is-a-geek-chisel/" target="_blank">Rob</a> and <a href="http://www.hanselman.com/blog/" target="_blank">Scott</a> for taking the time to answer me. I really appreciate it.<br />
<span id="more-43"></span></p>
<h2>A Word of Appreciation</h2>
<p>Let&#8217;s get something in perspective. Rob has actually <em>produced</em> something of immense value with SubSonic. I have just <em>complained </em>about it. Rob could very easily have just hammered me down, but he didn&#8217;t. Thanks, Rob.</p>
<p>Scott too.</p>
<p>In the <a href="http://www.hanselman.com/blog/HanselminutesPodcast98RaisingGeeksWithScottsDad.aspx" target="_blank">last episode of his most excellent podcast</a>, Scott said to his Dad that he likes to stir things up. &#8220;Presenting options&#8221; was the phrase I think he used. In that case, we are two peas in a pod. I <em>always</em> like to ask questions. If my question uncovers an unjustified assumption, things usually get better. If I&#8217;m wrong, then at least I come out knowing why I was wrong and understand the problem better.</p>
<p>While studying for my physics degree, I was asked to give feedback for a course on &#8220;Cosmic Dust&#8221;. I commented that it was just a completely pointless course. I mean, why waste 12 weeks of lectures studying the invisible dust floating around in space? Instead of numbing our brains with such useless information, we could have been learning something much more relevant. That particular comment, although made privately, really stirred up the lecturer. He got quite mad actually. He even wrote a long letter to the students with his  reasoning for why cosmic dust was so important. That itself was unprecedented. No lecturer had ever given us feedback to our feedback before.</p>
<p>Not much changed in the end, but at least I came out of it understanding more about what I&#8217;d been doing. Maybe that will happen with ASP.Net MVC.</p>
<p>So thanks to both of you for taking me seriously.</p>
<h2>How Dare They!</h2>
<p>Last month I watched a documentary about J.K. Rowling. It followed her as she completed and published the 7th and final Harry Potter book. It was the fasting selling book of all time. Truly amazing. But what amazed me most about the whole documentary was a comment made by two girls who had been queuing all night to get their copy of the book:</p>
<blockquote><p>&#8220;Finally! We&#8217;ve been waiting 10 years for this!&#8221;</p></blockquote>
<p>The remark was made with a tinge of disgust. It was as if the author had no right to take such a long time writing the book. How dare Mrs Rowling take so much time to finish her book while they had to suffer while sitting around waiting for it. How inconvenient for them! How inconsiderate of Mrs Rowling!</p>
<p>I thought, &#8220;if you wanted the book so much, why didn&#8217;t you write your own?&#8221;</p>
<p>In that spirit, I&#8217;m going to try to do something about the ASP.Net MVC thing myself. I don&#8217;t want to be that kind of person that complains but does nothing.</p>
<h2>Wait! There&#8217;s a baby in that bath-water!</h2>
<p>I read <a href="http://blog.wekeroad.com/2008/01/25/ramble-aspnet-mvc-is-a-geek-chisel/" target="_blank">Rob&#8217;s readers&#8217; comments</a>, and I think that it doesn&#8217;t require a full rewrite of ASP.Net to do what they want. In fact, I already wrote a bit of code, modeled loosely on <a href="http://www.djangoproject.com/documentation/templates/" target="_blank">Django templates</a>, which allows an ASP.Net developer to control the page output pretty much the same way as MVC promises to do. I&#8217;ll have to dig the code out of its hiding place, but then I plan to integrate it with a small Model-View-Presenter framework (a couple of generic base-classes for a Page and Presenter) which will enable a much better way for writing pages than the normal ASP.Net pages do. It also allows full testing of the controlling code.</p>
<p>And better yet, the MVP stuff is based on a refactored and simplified version of some Patterns and Practices code. (Yaaay, we can all be happy together!)</p>
<p>I&#8217;ve used this pattern, and each Presenter class is usually a few lines long. My ASP.Net page only contains presentation logic, i.e. stuff to render the page and retrieve input. I don&#8217;t need a controller nor a completely new framework to do it. In fact, a Controller class would be much worse, IMHO, because Controllers contain the code for more than one concern &#8211; a list page, an edit page, a delete page, etc. (I think that those things could be pragmatically abstracted and made easier anyhow, but that&#8217;s another story.) I personally prefer to keep my concerns separate.</p>
<p>And I&#8217;m not the only one who likes MVP. <a href="http://weblogs.asp.net/craigshoemaker/archive/2007/12/06/podcast-asp-net-mvc-and-the-future-of-model-view-presenter-interview-with-jeffery-palermo.aspx" target="_blank">Craig Shoemaker</a> does too.</p>
<p>So here&#8217;s my plan: I&#8217;ll try to publish some ideas and persuade you all to use them. Then I&#8217;ll get Microsoft to take Routes, Controllers, and whatever other goodies they&#8217;ve got in ASP.Net MVC, and put them in the next full-blown version of ASP.Net. Then everyone can use them and we can carry on with life as normal. I won&#8217;t have to use UrlRewriter to do my Routing any more and Microsoft can go back and finish off Workflow Foundation, ASP.Net Ajax, and Patterns and Practices.</p>
<p>Well, that&#8217;s the plan, anyway.</p>
<p>(I&#8217;ve just got to tidy up some of my code before I publish it. Give me a moment&#8230;)</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F01%2F28%2Faspnet-mvc-corollary-what-to-do%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/01/28/aspnet-mvc-corollary-what-to-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net Source Code Now Available</title>
		<link>http://www.richardbushnell.net/2008/01/17/net-source-code-now-available/</link>
		<comments>http://www.richardbushnell.net/2008/01/17/net-source-code-now-available/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 07:54:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[scott guthrie]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/01/17/net-source-code-now-available/</guid>
		<description><![CDATA[Scott Guthrie has just announced that the source code for the .Net framework has just been made available for reference use. It will be particularly useful to see how the controls in ASP.Net and Windows Forms have been done. Detailed instructions for how to set it up are here. One caveat: it&#8217;s not available for [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F01%2F17%2Fnet-source-code-now-available%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p><a href="http://weblogs.asp.net/scottgu" target="_blank">Scott Guthrie</a> has just announced that the source code for the .Net framework has <a href="http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx" target="_blank">just been made available for reference use</a>.</p>
<p>It will be particularly useful to see how the controls in ASP.Net and Windows Forms have been done.</p>
<p>Detailed instructions for how to set it up are <a href="http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx" target="_blank">here</a>.</p>
<p>One caveat: it&#8217;s not available for the Express editions of Visual Studio. Shame! I was just starting to have some fun with them too.</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2008%2F01%2F17%2Fnet-source-code-now-available%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2008/01/17/net-source-code-now-available/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Qualities of a .Net Application Design</title>
		<link>http://www.richardbushnell.net/2007/12/23/qualities-of-a-dot-net-application-design/</link>
		<comments>http://www.richardbushnell.net/2007/12/23/qualities-of-a-dot-net-application-design/#comments</comments>
		<pubDate>Sun, 23 Dec 2007 11:00:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Quaility]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[architecture software quality .net asp.net scalability]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/?p=8</guid>
		<description><![CDATA[I&#8217;m often asked to produce design documents for new applications. I can&#8217;t do this without discussing the advantages and disadvantages to each part of the design. A great way to do this is to focus on the desired qualities of the system you&#8217;re trying to build. Define the qualities you are trying to achieve, and [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2007%2F12%2F23%2Fqualities-of-a-dot-net-application-design%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>I&#8217;m often asked to produce design documents for new applications. I can&#8217;t do this without discussing the advantages and disadvantages to each part of the design. A great way to do this is to focus on the desired qualities of the system you&#8217;re trying to build. Define the qualities you are trying to achieve, and design each part of the system to match those qualities as best as possible.</p>
<p>It helps to have a list of things to consider. Here&#8217;s a list of some of the qualities you need to address for a .typical Net application:</p>
<h2></h2>
<h2>Development-Time Qualities</h2>
<ul>
<li><strong>Modifiability</strong> &#8211; (Often called &#8220;<strong>flexibility</strong>&#8220;, and especially important for agile development.) How easily can the software be modified to additional requirements and changes? Can changes be localized to as little code as possible? Do public interfaces have to change? How are the parts of the application dependent on one another? Are the most-likely-to-change areas of the application depended upon to be stable? To what extent are concerns separated?
<li><strong>Reusability</strong> &#8211; Can units of the application be reused elsewhere? Does the code fit the &#8220;DRY&#8221; principle (Don&#8217;t Repeat Yourself)? Does the system make good use of existing standards? Reusing code from other frameworks and systems can help keep testing and maintenance down, but reduce modifiability.
<li><strong>Portability</strong> &#8211; Could the system be easily ported to other platforms? This is often not an issue for most enterprise applications, as business requirements typically change more frequently than the technical platforms, and the .Net framework takes care of most of the issues. For a web application, portability could also include browser compatibility. What happens if the users suddenly receive an upgrade to their browsers?
<li><strong>Testability</strong> &#8211; How easy is it to prove that the application functions correctly, and that the various parts of the application do what they are supposed to do in isolation of one another? Can the application be tested automatically? Can the application eventually be tested easily end-to-end as part of an integration test? Can the application be load-tested?
<li><strong>Buildability</strong> &#8211; Can the application be built on systems other than those in the development environment? How often can it be built? The more often it can be built, the better. What tools can be used to do the builds? Can they implement continuous integration by building at every check-in? Which third-party controls or components are used? What part do licenses for third-party products play in the ability to build centrally?
<li><strong>Maintainability</strong> &#8211; How easy is it to understand the software for people other than the original developers? How easy is it to correct defects? Is the system documented enough to make it understandable?
<li><strong>Debugability</strong> &#8211; How easy is it to find out where and why there is an error in the system? How easy is it to find what is going wrong in a live, productive system?
<li><strong>Extensibility</strong> &#8211; How easy is it to extend the functionality of the system beyond its original specification?</li>
</ul>
<h2>Runtime Qualities</h2>
<ul>
<li><strong>Functionality</strong> &#8211; How well does the software help the users to do their work? Are there missing features which make the software useless? Does the software provide end-to-end support for a particular process?
<li><strong>Usability</strong> &#8211; How easy is it for users to understand and learn to use the software?&nbsp; Is the interface intuitive? Is there a supportive help system? Does the user interface match the users&#8217; needs? Are basic usability standards and conventions adhered to?
<li><strong>Performance</strong> &#8211; Does the system perform fast enough? How does it perform when multiple users are active? Where are the bottlenecks and latency in the system?
<li><strong>Concurrency</strong> &#8211; Is it possible for more than one user to use the system at a time? What is the performance impact of multiple sessions? Is state shared across the application, making the system unreliable?
<li><strong>Security</strong> &#8211; Does the system prevent unauthorized access or misuse? What happens if access is wrongly denied to a user? How easy can security be administrated? Does the STRIDE threat model show up any weaknesses? What is the potential outcome of a successful attack?&nbsp;
<li><strong>Integrity</strong> &#8211; This can be related to security, but it also refers to the data integrity of the system. Is the data always kept in a consistent state, or is it sometimes possible to infer different states of the system because of inconsistencies in the system? Do transactions pass the ACID test?
<li><strong>Reliability</strong> &#8211; Can the users rely on the software? Will it always perform correctly? Is it still usable at peak usage periods?
<li><strong>Availability</strong> &#8211; How often and for how long is the system available for use? How do upgrades affect its availability? Is the system meant to be used across time-zones?
<li><strong>Scalability</strong> &#8211; How does the software cope with adding more users over time? Can the system cope with an increase in the volume of data? What happens if the users start to use the system more often? Must the software scale up or can it scale out?
<li><strong>Deployability</strong> &#8211; How easy is it to deploy the initial release of the software? How easy is it to release future releases? Does software need to be replaced, or just patched? How does the deployment affect scalability?
<li><strong>Ugradability</strong> &#8211; Can a new version be deployed without stopping the normal operation of the system? What must be changed or upgraded when a new version is released? What third-party software may be upgraded which would affect the software?
<li><strong>Correctness</strong> &#8211; Does the software do exactly what was specified?
<li><strong>Conceptual Integrity</strong> &#8211; How balanced, simple, elegant, and practical is the whole system? Is there a clear vision as to what the software should do? Is the design consistent?
<li><strong>User Responsiveness</strong> &#8211; Related to performance and usability; how does the user perceive the application to be responding? Does the system stop responding for long periods of time, especially when retrieving data? Does the latency of parts of the system lead to decreased usability? Does the software use multiple threads to improve responsiveness?
<li><strong>Interoperability</strong> &#8211; How easily can the system be used with other systems?
<li><strong>Robustness</strong> &#8211; How does the system react to abnormal conditions? Does it crash, or recover gracefully? Do error messages baffle users and decrease usability?</li>
</ul>
<h2>Priorities</h2>
<p>Software qualities must always be balanced against one another. There&#8217;s no point in having performance good enough for MySpace.com if it&#8217;s not needed, for example, especially if it makes maintenance harder. Each quality has a particular importance for the system being developed. </p>
<p>In general the highest priority qualities are:</p>
<ul>
<li>Maintainability
<li>Correctness
<li>Reliability</li>
</ul>
<p>Also important for .Net Object-Oriented design are:</p>
<ul>
<li>Reusability
<li>Extensibility</li>
</ul>
<p>Most of what I focus on in my day-to-day work is focused on good maintainability and modifiability. Changes come along all the time, and the people paying for the software want them done fast. The faster you can adapt to their needs, the more they trust you, and the better your business relationship.</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2007%2F12%2F23%2Fqualities-of-a-dot-net-application-design%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2007/12/23/qualities-of-a-dot-net-application-design/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.Net MVC Framework leads you to extension method heaven</title>
		<link>http://www.richardbushnell.net/2007/12/12/aspnet-mvc-framework-made-public/</link>
		<comments>http://www.richardbushnell.net/2007/12/12/aspnet-mvc-framework-made-public/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 13:26:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://richardbushnell.net/?p=5</guid>
		<description><![CDATA[The first pre-release of new ASP.Net MVC (ahem, Ruby-on-Rails for .Net) framework has just been made public. I find it really exciting that Scott Guthrie and his team are listening to what the people want. Webforms is really quite heavy, especially in comparison to Ruby on Rails, so by offering new frameworks Microsoft will gain [...]]]></description>
			<content:encoded><![CDATA[
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2007%2F12%2F12%2Faspnet-mvc-framework-made-public%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<br><p>The first <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A9C6BC06-B894-4B11-8300-35BD2F8FC908&amp;displaylang=en">pre-release of new ASP.Net MVC</a> (ahem, Ruby-on-Rails for .Net) framework has just been made public.</p>
<p>I find it really exciting that Scott Guthrie and his team are listening to what the people want. Webforms is really quite heavy, especially in comparison to Ruby on Rails, so by offering new frameworks Microsoft will gain new developers. And new developers equals more servers, so it&#8217;s a good business model, methinks.</p>
<p>A major plus for me is seeing how the Framework shows off the new C# 3.0 features. I love Python and Ruby, but with no support yet for Visual Studio, it&#8217;s not easy to use them. Until now, the expressiveness of Python and Ruby have been missing from C# &#8211; it grew up from Java after all – but C# 3.0 is now moving towards that expressiveness too. With XAML and C#, things have really changed for developers over the past 5 or so years.</p>
<p>For example, check out <a href="http://blog.wekeroad.com/2007/12/05/aspnet-mvc-preview-using-the-mvc-ui-helpers/">this post</a> from <a href="http://blog.wekeroad.com/">Rob Conery</a>. He demonstrates an extension method which allows you to create a list of attributes as a string. You just call &#8220;ToAttributeList()&#8221; on any object, and you get a string back like &#8220;field1=&#8221;0&#8243; field2=&#8221;1&#8243;&#8221;.</p>
<p>I can already think of loads of places where I would like to use that. There&#8217;s already a &#8220;ToDictionary()&#8221; method in the .Net 3.5 Framework, which can be used to create a dictionary from a list of objects, using a field as the key, but I can create a dictionary directly using the property names as keys, with the objects as values.</p>
<p><span style="font-family:Consolas;font-size:9pt;"><span style="color:blue;">public </span><span style="color:blue;">static </span><span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:blue;">object</span>&gt; ToPropertyHash(<span style="color:blue;">this </span><span style="color:blue;">object</span> item)<br />
{<br />
<span style="color:blue;">  var</span> props = <span style="color:blue;">from</span> property <span style="color:blue;">in</span> item.GetType().GetProperties()<br />
<span style="color:blue;">              select </span><span style="color:blue;">new</span> {Name=property.Name, Value=property.GetValue(item, <span style="color:blue;">null</span>)};</span><br />
<span style="font-family:Consolas;font-size:9pt;"><span style="color:blue;">var</span> dict = <span style="color:blue;">new </span><span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:blue;">object</span>&gt;();</span><br />
<span style="font-family:Consolas;font-size:9pt;"><span style="color:blue;">foreach</span>(<span style="color:blue;">var</span> prop <span style="color:blue;">in</span> props)<br />
{<br />
dict.Add(prop.Name, prop.Value);<br />
}</span><br />
<span style="font-family:Consolas;font-size:9pt;"><span style="color:blue;">return</span> dict;<br />
}</span></p>
<p>Here&#8217;s testing code which demonstrates what you get.</p>
<p><span style="font-family:Consolas;font-size:9pt;"><span style="color:blue;">      var</span> myObject = <span style="color:blue;">new</span> { Name = <span style="color:#a31515;">&#8220;Frank&#8221;</span>, Age = 5 };<br />
<span style="color:blue;">var</span> dict = myObject.ToPropertyHash();<br />
<span style="color:#2b91af;">CollectionAssert</span>.Contains(dict.Keys, <span style="color:#a31515;">&#8220;Name&#8221;</span>);<br />
<span style="color:#2b91af;">CollectionAssert</span>.Contains(dict.Keys, <span style="color:#a31515;">&#8220;Age&#8221;</span>);<br />
<span style="color:#2b91af;">Assert</span>.AreEqual(dict[<span style="color:#a31515;">"Name"</span>], <span style="color:#a31515;">&#8220;Frank&#8221;</span>);<br />
<span style="color:#2b91af;">Assert</span>.AreEqual(dict[<span style="color:#a31515;">"Age"</span>], 5);</span></p>
<p>Maybe that&#8217;s not so interesting for you, but I am developing Windows Workflow Foundation apps, and a workflow instance always requires you to build a new dictionary with the names of the properties as keys. This could be very, very helpful to cut down on code for that.</p>
<p>Instead of …</p>
<p><span style="font-family:Consolas;font-size:9pt;"><span style="color:#2b91af;">      Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:blue;">object</span>&gt; args = <span style="color:blue;">new</span><span style="color:#2b91af;"> Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:blue;">object</span>&gt;();<br />
args.Add(<span style="color:#a31515;">&#8220;Name&#8221;</span>, <span style="color:#a31515;">&#8220;Richard Bushnell&#8221;</span>);<br />
args.Add(<span style="color:#a31515;">&#8220;Age&#8221;</span>, 32);<br />
args.Add(<span style="color:#a31515;">&#8220;NoOfKids&#8221;</span>, 5);<br />
</span></p>
<p>… I use:<span style="font-family:Consolas;font-size:9pt;"><span style="color:blue;"></span></span></p>
<p><span style="font-family:Consolas;font-size:9pt;"><span style="color:blue;">var</span> args = <span style="color:blue;">new</span> { Name = <span style="color:#a31515;">&#8220;Richard Bushnell&#8221;</span>, Age = 32, NoOfKids = 5 }.ToPropertyHash();</span></p>
<p>What I cannot understand yet, is why Microsoft has to copy Ruby On Rails? Don&#8217;t get me wrong, I love Rails. But in some places it just doesn&#8217;t suit ASP.net development. ASP.net developers already have their ways of working, and have bought controls, etc. Why force them to not use them anymore, if they just want to tidy up their code with a new MVC model? Wouldn&#8217;t it be best for everyone if they developed another kind of framework? The focus could be on testing, as with MVC, but more directed towards developers who already use WinForms and WebForms.</p>
<p>Microsoft <em>can</em> develop independently. Take LINQ, for example. The .Net team could have simply provided list comprehensions as implemented in Python, but instead, they came up with a totally new model which no other development framework has ever had. And while XAML is similar to the old Delphi DFM files, it&#8217;s still taken some good leaps forward. I don&#8217;t see that yet with the ASP.Net MVC Framework. They&#8217;re still playing catch-up with Rails.</p>
<p>In general though, I&#8217;m really excited to watch it developing.</p>

<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.richardbushnell.net%2F2007%2F12%2F12%2Faspnet-mvc-framework-made-public%2F&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="false" style="border:none; overflow:; width:450px; height:30px"></iframe>
<!-- using Like-Button-Plugin-For-Wordpress [v4.2] | by http://www.gb-world.net -->
]]></content:encoded>
			<wfw:commentRss>http://www.richardbushnell.net/2007/12/12/aspnet-mvc-framework-made-public/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

