<?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/" version="2.0"><channel><title>Derik Whittaker</title><link>http://devlicio.us/blogs/derik_whittaker/default.aspx</link><description>Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool
&lt;br /&gt;&lt;br /&gt;
&lt;div class="altnetgeekcode"&gt;&lt;a href="http://www.hanselman.com/altnetgeekcode/default.aspx?q=IOC(SM):MOC(RM):TDD(NU):SCC(Svn):ORM(L2S):XPP(-):XPP(+):DDD(T+)"&gt;IOC(SM):MOC(RM):TDD(NU):SCC(Svn):ORM(L2S):XPP(-):XPP(+):DDD(T+)&lt;/a&gt;&lt;/div&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DerikWhittakersBlog" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="derikwhittakersblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Sharing Code Analysis files between projects in Visual Studio 2010</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/03/10/sharing-code-analysis-files-between-projects-in-visual-studio-2010.aspx</link><pubDate>Wed, 10 Mar 2010 11:13:43 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55827</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55827</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55827</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/03/10/sharing-code-analysis-files-between-projects-in-visual-studio-2010.aspx#comments</comments><description>&lt;p&gt;The ability to have static code analysis (aka run FXCop inside the IDE) is not something that is new to Visual Studio 2010.&amp;#160; What is new is the simplicity in which you can share the exact same configuration across all of your projects at once.&lt;/p&gt;  &lt;p&gt;Prior to VS2010 if you wanted to share your config it was not possible (from what I have ever seen).&amp;#160; With VS2008 each .proj file contained a section in the file which laid out each rule that should/should not be turned on.&amp;#160; If you wanted to share these what you needed to do was open up each .proj file in a text editor and copy/paste the rules.&amp;#160; As you could image, copy and pasting this could get old real fast.&amp;#160; In fact I would even argue that I may even prevent you from wanted to use the built in analysis all together.&lt;/p&gt;  &lt;p&gt;Here comes Visual Studio 2010 to the rescue.&amp;#160; In 2010 you can save your rules to a .ruleset file and you can import this same file into all your projects.&amp;#160; No more need for copy/paste by hand.&lt;/p&gt;  &lt;p&gt;Steps To Do This:&lt;/p&gt;  &lt;p&gt;Step 1: Open up the Code Analysis tab in the project properties.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_2521C5A0.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_6ED09D90.png" width="364" height="214" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Step 2: In the drop down choose Browse&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_0BF6459B.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_5FD948A9.png" width="364" height="223" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Step 3: Find your .ruleset file on disk&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_15FAC0F9.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_632ABA84.png" width="364" height="224" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Step 4: Rinse and Repeat for all your other projects.&lt;/p&gt;  &lt;p&gt;Now that having the ability to share your rule set across projects is painless you have NO excuse not to utilize this feature.&lt;/p&gt;  &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55827" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development+Tools/default.aspx">Development Tools</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/.Net+IDE/default.aspx">.Net IDE</category></item><item><title>Providing Metadata to your MEF exports</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/03/06/providing-metadata-to-you-mef-exports.aspx</link><pubDate>Sun, 07 Mar 2010 01:07:24 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55689</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55689</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55689</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/03/06/providing-metadata-to-you-mef-exports.aspx#comments</comments><description>&lt;p&gt;Many months ago I created a post on how to get started with &lt;a href="http://devlicio.us/blogs/derik_whittaker/archive/2009/10/27/simple-kick-start-example-using-mef-preview-8.aspx"&gt;MEF&lt;/a&gt;.&amp;#160; Ever since then I have been meaning to get this post (and others) about about how to get up and running quickly with MEF.&lt;/p&gt;  &lt;p&gt;In this post will demonstrate how to provide Metadata (custom values which can help provide context) information to your Exported item.&amp;#160; Why should you care about Metedata?&amp;#160; Below is a great reason from the MEF site on codeplex&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://mef.codeplex.com/wikipage?title=Declaring%20Exports&amp;amp;referringTitle=Exports%20and%20Metadata"&gt;Declaring Exports&lt;/a&gt; explained the basics of parts exporting services and values. In some cases it’s necessary to associate information with exports for a variety of reasons. Commonly it’s used to explain about the capabilities of an specific implementation of a common contract. This is useful to allow imports to either constraint the export that can satisfy it, or to import all available implementations at the time and check their capabilities in runtime before using the export.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;Before we get rolling:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;What I am going to show in this post is how to create a custom Export Attribute.&amp;#160; It is possible to expose Meta via the build in ExportAttribute, but the built in mechanism has a few short comings:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Not discoverable &lt;/li&gt;    &lt;li&gt;Not strongly typed &lt;/li&gt;    &lt;li&gt;Compiler cannot validate the data content &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;strong&gt;Lets get rolling:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Pre-Step 1: Taking a look at the Class which we will mark as a Export&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="c-sharp" name="code"&gt;    public interface IPlugin
    {
        string PluginAction();
    }

    [Export(typeof(IPlugin))]
    public class DefaultPlugin : IPlugin 
    {
        public string PluginAction()
        {
            return &amp;quot;This is the default plugin&amp;quot;;
        }
    }&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Defining the interface which will represent your&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In order to create discoverable Metadata you will first want to create an interface which will represent your metadata.&amp;#160; Below is my interface.&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;    public interface IPluginMetaData
    {
        string Name { get; }
        string Version { get; } 
    }&lt;/pre&gt;

&lt;p&gt;We will later use this interface when we define and use our custom Export Attribute.&amp;#160; The main reason for creating this attribute is now the compiler has a hard wired way to know exactly what type of data is being exposed in your Metadaa&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Defining your custom ExportAttribute Attribute&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we created our interface to give us strong typing and discoverability we need to create a custom attribute which will allows the MEF engine to know we have Metadata to expose&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;    [MetadataAttribute]
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class PluginMetadataAttribute : ExportAttribute
    {
        public PluginMetadataAttribute( string name, string version)
            : base(typeof(IPluginMetaData))
        {
            Name = name;
            Version = version;
        }

        public string Name { get; set; }
        public string Version { get; set; }
    }&lt;/pre&gt;

&lt;p&gt;When looking at the code above there are 3 things to pay close attention to&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;You need to make a call into the base constructor of the ExportAttribute and provide it the type of your interface which defines your Metadata &lt;/li&gt;

  &lt;li&gt;You need to mark your attribute with the [MetadataAttribute] (which is part of MEF) &lt;/li&gt;

  &lt;li&gt;You need to mark the usage type of your attribute.&amp;#160; I am not 100% why this is needed (Glenn, you out there with an answer???) &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Providing your Metdata to your Exported Class&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;    [Export(typeof(IPlugin))]
    [PluginMetadata(&amp;quot;Default&amp;quot;, &amp;quot;1.0.0.0&amp;quot;)]
    public class DefaultPlugin : IPlugin 
    {
        public string PluginAction()
        {
            return &amp;quot;This is the default plugin&amp;quot;;
        }
    }&lt;/pre&gt;

&lt;p&gt;The code above is the same as the code we saw in pre-step 1, but this time we have marked the class with our custom Metadata attribute.&amp;#160; We have now officially provided our Metadata to our Export…. But how do we get this information out of MEF?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Setting up your [ImportMany] to use the Metadata&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are using an ImportMany (this should also work on an Import, but I have never tried) most likely you are pushing your Exports into a IList or IEnumerable.&amp;#160; If this is the case, your changes are pretty minor.&amp;#160; Below is what you need to do in order to have your Metadata loaded.&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;[ImportMany(typeof(IPlugin), AllowRecomposition = true)]
private IList&amp;lt;Lazy&amp;lt;IPlugin, IPluginMetaData&amp;gt;&amp;gt; _loadedIPlugins = new List&amp;lt;Lazy&amp;lt;IPlugin, IPluginMetaData&amp;gt;&amp;gt;();&lt;/pre&gt;

&lt;p&gt;If you have not seen the &lt;a href="http://msdn.microsoft.com/en-us/library/dd642331%28VS.96%29.aspx"&gt;Lazy&lt;/a&gt; keyword, you are not alone.&amp;#160; This is new to .Net 4 and this provides Lazy initialization support to the framework.&amp;#160; (part of the System namespace).&amp;#160; One key thing to understand here though is that the Lazy keyword out the box is only Lazy&amp;lt;T&amp;gt;, but the Lazy we are using is Lazy&amp;lt;T, M&amp;gt;.&amp;#160; This extended version of Lazy lives in the MEF assemblies (System.ComponentModel.Composition) and will need to be referenced to use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Using the Metadata&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you have the Export loaded into your container (which by the way does not need to change to have this work) you can access your container by selecting the .Metadata property on your instance of the export.&amp;#160; The image below shows it in action.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_0421BA20.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_639A7A6D.png" width="180" height="151" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, exposing and using Metadata via MEF is a snap.&amp;#160; &lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55689" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development+Tools/default.aspx">Development Tools</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/MEF/default.aspx">MEF</category></item><item><title>Coding Concepts are Cross Language, because it is SQL does not means it should suck</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/03/01/coding-concepts-are-cross-language-just-because-it-is-sql-means-it-can-suck.aspx</link><pubDate>Mon, 01 Mar 2010 11:49:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55578</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55578</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55578</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/03/01/coding-concepts-are-cross-language-just-because-it-is-sql-means-it-can-suck.aspx#comments</comments><description>&lt;p&gt;&amp;lt;Warning_Rant_AHead&amp;gt;&lt;/p&gt;
&lt;p&gt;Today I was reviewing some commits by our team and I ran into one commit in general that first made me vomit a bit in my mouth, then get pissed as all hell that we committed code like this.&lt;/p&gt;
&lt;p&gt;The code that was committed was a minor change to one of our &amp;lsquo;legacy&amp;rsquo; (aka has no tests, written like a blind monkey coded it and god help the person who has to make changes to it) stored procs.&amp;nbsp; Here are some details on the proc&lt;/p&gt;
&lt;p&gt;Has about 2050 lines of code 
  &lt;br /&gt;Has about 141 variables 
  &lt;br /&gt;Has 6 Temp tables 
  &lt;br /&gt;Has &amp;gt; 50 update statements 
  &lt;br /&gt;Has ~13 delete statements 
  &lt;br /&gt;Has 8 Cursors&lt;/p&gt;
&lt;p&gt;What makes me so mad is that this code when it was originally written was code reviewed by a senior developer on the team (I know this be cause like many other old school shops at that time we put our commit comments in the header of every file).&amp;nbsp; I am going to bet the farm that had this been C# code and not SQL this would not have passed review.&amp;nbsp; BUT for what ever reason SQL seems to be treated differently.&amp;nbsp; When writing SQL many people throw best practices out the window, and I have NO clue why.&lt;/p&gt;
&lt;p&gt;The one message I want to get across to anyone out there reading this is&amp;hellip;. Code is Code and coding concepts are cross language.&amp;nbsp; If while writing .net/java/ruby/etc code you follow practices like SRP, DRY, etc then why not follow those same principles when writing code in SQL (or any language for that fact)&lt;/p&gt;
&lt;p&gt;&amp;lt;/Warning_Rant_AHead&amp;gt;&lt;/p&gt;
&lt;p&gt;Till next time&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55578" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Best+Practice/default.aspx">Best Practice</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Rant/default.aspx">Rant</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Craftsmanship/default.aspx">Craftsmanship</category></item><item><title>Issues Compiling VS2010 solutions (with web projects) from Nant</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/27/issues-compiling-vs2010-solutions-with-web-projects-from-nant.aspx</link><pubDate>Sat, 27 Feb 2010 14:40:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55572</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55572</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55572</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/27/issues-compiling-vs2010-solutions-with-web-projects-from-nant.aspx#comments</comments><description>&lt;p&gt;Recently I upgraded a project of mine (the &lt;a href="http://www.dimecasts.net/Home"&gt;Dimecasts&lt;/a&gt; code base) to use VisualStudio 2010.&amp;nbsp; In the process everything worked just fine from the IDE, but when I tried to compile it from the command line I would get the following errors:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Error MSB4064: The &amp;quot;Retries&amp;quot; parameter is not supported by the &amp;quot;Copy&amp;quot; task. 
    &lt;br /&gt;Error MSB4063: THe &amp;quot;Copy&amp;quot; task could be initialized with its input parameter.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;After a bit a googling I came across a post which (and of course i cannot find it now) said that if you open up your .proj files and change the line that pointed to the v10.0 build of web applications and reset it back to 9.0 everything would compile.&amp;nbsp; And this did work... BUT when you try to open that project up again in VS 2010 it will simply revert your changes... this is not a working solution.&lt;/p&gt;
&lt;p&gt;
  &lt;br /&gt;Next I decided to switch my target framework in Nant from 3.5 to 4.0, but of course my nant.exe.config file does not support 4.0 yet.&amp;nbsp; So after a bit more googling I found this &lt;a href="http://paigecsharp.blogspot.com/2009/08/nant-net-framework-40-configuration.html"&gt;post&lt;/a&gt; that gives details on how to add the missing values to the config file.&lt;/p&gt;
&lt;p&gt;When I added the config information to my Nant.exe.config file things were better, but still not great.&amp;nbsp; Now I was getting an error that said:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;
    &lt;br /&gt;The &amp;quot;vendor&amp;quot; attribute does not exist, or has no value.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
  &lt;br /&gt;To resolve this I added the following under the &amp;lt;framework&amp;gt; node in my config 

  &lt;br /&gt;vendor=&amp;quot;Microsoft&amp;quot; 

  &lt;br /&gt;

  &lt;br /&gt;After this I got another error.... This time it said that .Net Framework 4.0 was not installed.&amp;nbsp; But I know this is not valid.&amp;nbsp; After looking at the information for a few more seconds I realized the issue.&amp;nbsp; The example config from the post above was build on an older version of the 4.0 framework (.20506) and I have .30128. 

  &lt;br /&gt;

  &lt;br /&gt;I changed all values in the nant.exe.config value that was v4.0.20506 to be v4.0.30128 and NOW I am able to compile.&lt;/p&gt;
&lt;p&gt;So long story short, if you are getting the MSB4064 error you need to do the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Point nant to use the 4.0 framework tools &lt;/li&gt;
&lt;li&gt;Follow this &lt;a href="http://paigecsharp.blogspot.com/2009/08/nant-net-framework-40-configuration.html"&gt;post&lt;/a&gt;&amp;nbsp; and copy the framework section to your Nant.exe.config file &lt;/li&gt;
&lt;li&gt;Add the missing &amp;#39;vendor&amp;#39; attribute to the new framework section &lt;/li&gt;
&lt;li&gt;Update the version in the new framework section to match the version you have on disk (check C:\Windows\Microsoft.NET\Framework for versions) &lt;/li&gt;
&lt;li&gt;Compile again &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
  &lt;br /&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55572" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development+Tools/default.aspx">Development Tools</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/.Net+IDE/default.aspx">.Net IDE</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/.Net/default.aspx">.Net</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Nant/default.aspx">Nant</category></item><item><title>Noisy code does not equal clean code</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/25/noisy-code-does-not-equal-clean-code.aspx</link><pubDate>Fri, 26 Feb 2010 01:16:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55546</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>11</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55546</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55546</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/25/noisy-code-does-not-equal-clean-code.aspx#comments</comments><description>&lt;p&gt;Today I was having a conversation with one of the developers on my team (btw, this guy is going to be a rock star) and I made that statement to him that I thought we had some noisy code.&amp;#160; The context around this conversation was with our usage of &lt;a href="http://www.codeplex.com/AutoMapper"&gt;AutoMapper&lt;/a&gt; (which I love so DO NOT take this as a slight against the tool) and how by default using AutoMapper exposes too much noise and I do not like it.&lt;/p&gt;  &lt;p&gt;When I made this statement to him he was not 100% sure what I meant, so in place of having a one-off conversation with him I thought I would try to explain my thoughts to the world (hey, that is the point of blogging after all, right).&lt;/p&gt;  &lt;p&gt;When using AutoMapper to map objects from one type to another in your code you need to implement something like below:&lt;/p&gt;  &lt;pre&gt;&lt;em&gt;var someMappedDto = Mapper.Map&amp;lt;SomeModel, SomeDto&amp;gt;(someModelInstance);&lt;/em&gt;&lt;/pre&gt;

&lt;p&gt;If you look at the code there is a bit of noise here in my opinion. So what do I mean by noise? I consider anything in my code that gets in my way or does not provide me direct feedback as noise.&lt;/p&gt;

&lt;p&gt;In the line above I consider the following noise:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Mapper.Map – I do not like this because having Mapper.Map sprinkled all over my code base just means that my code has too much knowledge of the actually mapping library we use, this is noise.&amp;#160; Hey, it was for this basic concept that the &lt;a href="http://www.codeplex.com/CommonServiceLocator"&gt;Common Service Locator&lt;/a&gt; was created to help prevent&lt;/li&gt;

  &lt;li&gt;Having to provide both the source type AND the destination type – The source type should be able to be derived from the source object instance (in cases where you do not want to use the mapper for some child type of the source type).&amp;#160; I concede that you do need to provide the destination type other wise we would have no clue what you want in the end&lt;/li&gt;

  &lt;li&gt;Having to provide the source type instance in the constructor.&amp;#160; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In order to reduce the noise, and make for cleaner code I would like to see something like&lt;/p&gt;

&lt;p&gt;&lt;em&gt;var someMappedDto = someModelInstance.Map&amp;lt;SomeDto&amp;gt;();&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In my humble opinion the code above is cleaner and more concise.&amp;#160; The code above has less noise to distract me from my coding efforts.&amp;#160; In particular the code above addresses my 3 issues in regards to the noise&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Now I am abstracting my mapping library of choice (AutoMapper) away into an extension method some place, thus giving me a clean abstraction layer&lt;/li&gt;

  &lt;li&gt;I do not need to provide the source data type as it can be inferred from the instance itself (yes, only in the case where the actual type being used is the type I want)&lt;/li&gt;

  &lt;li&gt;No need to provide the type to be mapped from (well not directly)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;To me noise free code is clean, concise and easy to read.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55546" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Opinion/default.aspx">Opinion</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Craftsmanship/default.aspx">Craftsmanship</category></item><item><title>Hey, NHibernate give me back my milliseconds</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/22/hey-nhibernate-give-me-back-my-milliseconds.aspx</link><pubDate>Mon, 22 Feb 2010 22:47:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55492</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55492</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55492</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/22/hey-nhibernate-give-me-back-my-milliseconds.aspx#comments</comments><description>&lt;p&gt;Have you ever noticed that out of the box NHibernate&amp;rsquo;s DateTime type will truncate/ignore your milliseconds for DateTime fields?&amp;nbsp; If you do not believe me check out this &lt;a href="https://www.hibernate.org/hib_docs/nhibernate/html/mapping.html#mapping-types-basictypes"&gt;post&lt;/a&gt;.&amp;nbsp; If you think about why it does this it will become clear, NHibernate runs against MANY databases and each one of them stores DateTime values slightly different.&amp;nbsp; However all of them store basic YYYY-MM-DD : HH:MM:SS.&lt;/p&gt;
&lt;p&gt;If you google how to resolve this issue you will find a few a &lt;a href="http://www.mostlyclean.com/post/2007/11/Increasing-DateTime-storage-precision-in-Nhibernate-%28and-Castle-ActiveRecord%29.aspx"&gt;post&lt;/a&gt; that suggests you create a custom User Type (IUserType).&amp;nbsp; Although I am sure this will work, this just seems like such overkill for the problem.&lt;/p&gt;
&lt;p&gt;What I was able to do was setup my mapping in FluentNHibernate as such&lt;/p&gt;
&lt;p&gt;Map( x =&amp;gt; x.MyField, &amp;quot;My_Field&amp;quot; ).CustomTypeIs(&amp;quot;timestamp&amp;quot;);&lt;/p&gt;
&lt;p&gt;By adding the .CustomTypeIs attribute (i tried CustomSqlTypeIs but this did not work) NHibernate was able to save my DateTime property into a DateTime (not Timestamp or DateTime2) field with the milliseconds inplace.&lt;/p&gt;
&lt;p&gt;Hope this helps,&lt;/p&gt;
&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55492" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/FluentNhibernate/default.aspx">FluentNhibernate</category></item><item><title>Registration Error while Hosting WCF Services in a Windows Server</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/11/registration-error-while-hosting-wcf-services-in-a-windows-server.aspx</link><pubDate>Thu, 11 Feb 2010 19:46:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55354</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55354</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55354</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/11/registration-error-while-hosting-wcf-services-in-a-windows-server.aspx#comments</comments><description>&lt;p&gt;Have you ever run into the following error while trying to host (start) a WCF service inside a Windows Service?&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Starting WCF Services step has caused the following error HTTP could not register URL &lt;a href="http://+:9997//Services/HashGenerationService/"&gt;http://+:9997//Services/HashGenerationService/&lt;/a&gt;. Your process does not have access rights to this namespace (see &lt;a href="http://go.microsoft.com/fwlink/?LinkId=70353"&gt;http://go.microsoft.com/fwlink/?LinkId=70353&lt;/a&gt; for details).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If you have you are not along. Also, if you have clicked on the link for MS and felt like that was absolutely NO help, you still are not alone.&lt;/p&gt;
&lt;p&gt;The simplest (maybe not the best) way to solve this issue is to configure your windows service (the one hosting your WCF services) to log on as &amp;lsquo;Local System Account&amp;rsquo; as below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_345EDE79.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="image" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_480BC80D.png" border="0" height="395" width="364" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Once you have done this try restarting your service and see if your wcf services start as expected.&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;
&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55354" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Help_210021002100_/default.aspx">Help!!!</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/WCF/default.aspx">WCF</category></item><item><title>Removing Generated code from NCover Reports</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/11/removing-generated-code-from-ncover-reports.aspx</link><pubDate>Thu, 11 Feb 2010 13:12:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55348</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55348</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55348</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/11/removing-generated-code-from-ncover-reports.aspx#comments</comments><description>&lt;p&gt;If you are a user of NCover you know it has great power and that it can generate great results.&amp;nbsp; But what do you do if you do not want to include certain items in your coverage report?&amp;nbsp; In particular what do you do if you have generated code (say WCF Proxy code) which you do not want to skew your coverage numbers?&lt;/p&gt;
&lt;p&gt;Simple, you exclude them right :)&lt;/p&gt;
&lt;p&gt;If you are simply using the NCover Explorer this is easy, you can right click the namespace/type and say exclude.&amp;nbsp; But what if you are using NCover from the command line?&amp;nbsp; Well this is also simple.&lt;/p&gt;
&lt;p&gt;All you need to do is use the &lt;span style="color:#0000ff;"&gt;excludeAttributes&lt;/span&gt; option for NCover.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_3F27F811.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="image" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_25BFF4D7.png" border="0" height="145" width="644" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The code above is what we use to generate our NCover reports, the important part is how we are using excludeAttributes.&amp;nbsp; Now I know you are saying, wait you have a property being called, I want to see the &amp;lsquo;real&amp;rsquo; value.&amp;nbsp; Well it is below&lt;/p&gt;
&lt;p&gt;excludeAttributes=&amp;rdquo;System.CodeDom.Compiler.GeneratedCodeAttribute&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Adding the code above will tell NCover to exclude any code with the above attribute (which should be good for WCF Proxies).&lt;/p&gt;
&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55348" width="1" height="1"&gt;</description></item><item><title>Help my DataContracts do not show up in my WCF Services</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/09/help-my-datacontracts-do-not-show-up-in-my-wcf-services.aspx</link><pubDate>Tue, 09 Feb 2010 11:28:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55324</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55324</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55324</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/02/09/help-my-datacontracts-do-not-show-up-in-my-wcf-services.aspx#comments</comments><description>&lt;p&gt;The other day I refreshed one of our WCF services (right click the service and do a Update Service Reference) and all of a sudden I got a metric crap-ton of build errors. In each place I received the error it told me that the type was not found.&amp;nbsp; At first I could not understand what was going on, in fact I was sure the compiler was playing tricks on me (cause we all the compiler has a devilish sense of humor) because how could it be possible that all of my types went missing.&lt;/p&gt;
&lt;p&gt;Just to be sure I took a look at the generated code in the Reference.cs class and sure enough all my types were missing. &lt;/p&gt;
&lt;p&gt;Now that I know the compiler is not just playing tricks on me it was time to find out what happened.&lt;/p&gt;
&lt;p&gt;The first thing I did was to try recompiling the service and updating my references again, but as you could have guessed this did not solve my problem.&amp;nbsp; Next I decided to try to create a duplicate reference to the service to see if maybe my original reference was screwed up, and as you may have guess the new reference also was missing my types (shocking I know).&amp;nbsp; At this point I was a bit stumped, and did not know exactly what could have caused the issue.&amp;nbsp; I next decided to take a look at the service configuration so I right clicked on the service and selected &amp;lsquo;Configure Service Reference&amp;rsquo;.&amp;nbsp; When I did this the screen below appeared&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_1256B0D3.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="image" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_3F6B9DA1.png" border="0" height="386" width="424" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After looking at this for a few minutes it dawned on me what had happened.&amp;nbsp; The check box (one circled in red) was selected (and is by default) and someone on the team had added direct reference to the assembly which contained my Models that were provided via the web service.&amp;nbsp; I decided to uncheck that check box and give that a whirl and sure enough my Models came pack.&amp;nbsp; Now that I was back up and running, it was time to remove the direct reference from my project to the assembly which hosts my WCF service as there is no point in both referring to it locally as well as hitting it via a service.&lt;/p&gt;
&lt;p&gt;Long story short, if you refresh your WCF reference and all your Data Contract Models disappear there are 2 things you need to look for. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Are you referencing the service assembly locally (if so why?)&lt;/li&gt;
&lt;li&gt;Do you have the &amp;lsquo;reuse types&amp;rsquo; check box selected in the WCF configuration screen?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If either (or both) of the above are set then you should have your solution.&lt;/p&gt;
&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55324" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/WCF/default.aspx">WCF</category></item><item><title>MEF and decrypting LoaderExceptions</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/31/mef-and-decrypting-loaderexceptions.aspx</link><pubDate>Sun, 31 Jan 2010 14:51:02 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55224</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55224</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55224</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/31/mef-and-decrypting-loaderexceptions.aspx#comments</comments><description>&lt;p&gt;Have you ever received the following exception while using &lt;a href="http://www.codeplex.com/MEF"&gt;MEF&lt;/a&gt;?&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;if you have received this error did you scratch your head and wonder ‘what the F does this mean’?&amp;#160; Well the long and short of it is this.&amp;#160; This means that while trying to load an &lt;a href="http://mef.codeplex.com/wikipage?title=Declaring%20Exports&amp;amp;referringTitle=Guide"&gt;Export&lt;/a&gt; there was a dependency which could not be found during reflection.&lt;/p&gt;  &lt;p&gt;The quick way to determine the cause of the error is to do as the image below shows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/MEFException_5F00_54EB0696.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="MEFException" border="0" alt="MEFException" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/MEFException_5F00_thumb_5F00_0B78B1DB.png" width="804" height="104" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;What I would suggest is to wrap your MEF logic inside of a try-catch and explicitly catch &lt;a href="http://msdn.microsoft.com/en-us/library/system.reflection.reflectiontypeloadexception.aspx"&gt;ReflectionTypeLoadException&lt;/a&gt;.&amp;#160; Inside of your catch add some logic as such (just a PoC, copy-paster beware).&lt;/p&gt;  &lt;pre class="C#" name="code"&gt;catch (ReflectionTypeLoadException tLException)
{
    var loaderMessages = new StringBuilder();
    loaderMessages.AppendLine(&amp;quot;While trying to load composable parts the follwing loader exceptions were found: &amp;quot;);
    foreach (var loaderException in tLException.LoaderExceptions)
    {
        loaderMessages.AppendLine(loaderException.Message);
    }

    // this is one of our custom exception types.
    throw new PluginLoadingException(loaderMessages.ToString(), tLException);
}&lt;/pre&gt;

&lt;p&gt;As you can see when you look at the LoaderExcpetions collections from my image above I had forgotten to reference AutoMapper in my plug-in and all hell broke lose (btw, no idea how this even compiled, but that is a different post).&lt;/p&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55224" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/MEF/default.aspx">MEF</category></item><item><title>Duplicated columns in generated sql from NHibernate</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/25/duplicated-columns-in-generated-sql-from-nhibernate.aspx</link><pubDate>Mon, 25 Jan 2010 13:57:25 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55126</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55126</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55126</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/25/duplicated-columns-in-generated-sql-from-nhibernate.aspx#comments</comments><description>&lt;p&gt;I was trying to profile some NHibernate sql to see if we could make some improvements.&amp;#160;&amp;#160; One thing I noticed very shortly after starting this task was that one of my columns was being duplicated.&amp;#160; Now this is NOT going to make a huge performance difference but was something I wanted to remove this as it felt ‘wrong’.&amp;#160; Below is the original sql segment&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre class="sql" name="code"&gt;resrole1_.PART_B_PROVIDER_NO             as PART16_29_0_,
resrole1_.ADMIN_SET_ID                   as ADMIN17_29_0_,
resrole1_.NATIONAL_PROVIDER_ID           as NATIONAL18_29_0_,
resrole1_.Admin_Set_ID                   as Admin17_29_0_,
resrole1_.Resource_Type                  as Resource19_29_0_,&lt;/pre&gt;

&lt;p&gt;The first thing I looked at when I started to look for the cause was the mapping for the entity (Role entity) to make sure the ‘Admin_Set_ID’ is not mapped multiple times.&amp;#160; And of course it was not.&amp;#160; After a few minutes of staring at the screen (everyone knows this is how all the hard problems are solved) it dawned on me that Admin_Set_ID was a FK from one of my associations.&amp;#160; Below is my association that was using it.&lt;/p&gt;

&lt;pre class="C#" name="code"&gt;References( x =&amp;gt; x.ResourceType )
	.Access.AsCamelCaseField( Prefix.Underscore )
        .WithColumns( &amp;quot;Admin_Set_ID&amp;quot;, &amp;quot;Resource_Type&amp;quot; )
        .FetchType.Select()
        .LazyLoad();&lt;/pre&gt;

&lt;p&gt;Because Admin_Set_Id is a FK I should NOT have been mapping as part of my entity.&amp;#160; When I removed this column from my entity so that I could get it as part of my association.&amp;#160; When I did this my newly outputted sql looked like below:&lt;/p&gt;

&lt;pre class="sql" name="code"&gt;resrole1_.PART_B_PROVIDER_NO             as PART16_29_0_,
resrole1_.ADMIN_SET_ID                   as ADMIN17_29_0_,
resrole1_.NATIONAL_PROVIDER_ID           as NATIONAL18_29_0_,
resrole1_.Resource_Type                  as Resource19_29_0_,&lt;/pre&gt;

&lt;p&gt;Long story short is this.&amp;#160; If you happen to see a column being duplicated in your generated sql make sure that you are not referencing/mapping a FK directly in your mappings.&amp;#160; &lt;/p&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55126" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/NHibernate/default.aspx">NHibernate</category></item><item><title>Passing NULL into Overloaded Methods in unit tests…</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/21/passing-null-into-overloaded-methods-in-unit-tests.aspx</link><pubDate>Thu, 21 Jan 2010 12:08:31 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55104</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55104</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55104</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/21/passing-null-into-overloaded-methods-in-unit-tests.aspx#comments</comments><description>&lt;p&gt;Today I was adding some new logic to some older code and I noticed there was very little test coverage on the logic so I decided to add some.&amp;#160; As I was adding coverage I wanted to add some tests that proved out our &lt;a href="http://research.microsoft.com/en-us/projects/contracts/"&gt;Contract&lt;/a&gt; style bound checks.&amp;#160; However there was one slight problem.&amp;#160; The method(s) I wanted to add coverage to was overloaded as such:&lt;/p&gt;  &lt;pre class="c#" name="code"&gt;public virtual IMessageTransporter GetTransporter( Destination destination )
{
    // The null transporter will allow for testing without hittng rhapsody or an engine
    if ( ConfigurationReader.UseNullTransporter ) { return new NullTransporter(); }

    Contracts.Requires( destination != null );
    
    // for now we only have one transporter for now.... will add more later
    return new HttpTransporter( destination.Endpoint );

}&lt;/pre&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;public virtual IMessageTransporter GetTransporter( Endpoint endpoint )
{
    // The null transporter will allow for testing without hittng rhapsody or an engine
    if ( ConfigurationReader.UseNullTransporter ) { return new NullTransporter(); }

    Contracts.Requires( endpoint != null );
    
    // for now we only have one transporter for now.... will add more later
    return new HttpTransporter( endpoint  );

}&lt;/pre&gt;

&lt;p&gt;As you can see from the 2 methods above they are the same with ONLY the provided parameter being different.&amp;#160; When I started to write my tests I did this:&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;transporterFactory.GetTransporter( null );&lt;/pre&gt;

&lt;p&gt;But when I simply added NULL as the parameter the compiler provided me the following error&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The call is ambiguous between the following methods or properties: ‘TransporterFactory.GetTransporter(Destination)&amp;#39; and TransporterFactory.GetTransporter(Endpoint)&amp;#39;&amp;#160;&amp;#160;&amp;#160; C:\PathHere\TransporterFactoryTests.cs&amp;#160;&amp;#160;&amp;#160; 13&amp;#160;&amp;#160;&amp;#160; 45&amp;#160;&amp;#160;&amp;#160; Common.Tests&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now if you think about it for even 2 seconds the above error makes perfect sense.&amp;#160; So the real question is how do you get around this….?&amp;#160; Simple you do the following.&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;transporterFactory.GetTransporter( (Destination)null );&lt;/pre&gt;

&lt;p&gt;By providing a type on your call the compiler now will know which overload you are attempting to call and the world will be a happier place.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55104" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/.Net/default.aspx">.Net</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category></item><item><title>A new feature request for C# I would like is fall through exceptions</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/20/a-new-feature-request-for-c-i-would-like-is-fall-through-exceptions.aspx</link><pubDate>Wed, 20 Jan 2010 23:58:16 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55086</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>17</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=55086</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=55086</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/20/a-new-feature-request-for-c-i-would-like-is-fall-through-exceptions.aspx#comments</comments><description>&lt;p&gt;Now before you write off this post as being ‘just another silly request’ hear me out.&lt;/p&gt;  &lt;p&gt;Right now in C# we can do the following &lt;/p&gt;  &lt;pre class="c#" name="code"&gt;switch( someObject )
{
	case Option1:
	case Option2:
	case Option3:
		// do something
		break;
	case Option4:
		// do something
		break:
} &lt;/pre&gt;

&lt;p&gt;Allowing fall through for a switch statement is a powerful technique.&amp;#160; It allows for multiple case statements in the same switch block to use the exact same logic, oh, and it also allows for code reduction.&lt;/p&gt;

&lt;p&gt;Given the fact that we can do this with a switch statement why can we not do this with try-catch statements?&amp;#160; &lt;/p&gt;

&lt;p&gt;As an example(s) (or a suggestion of syntax) why could we not have the following&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;try
{

} catch ( SomeException1 ) {
} catch ( SomeException2 ) {
} catch ( SomeException3 ) {
} catch ( SomeException4 se ) { 
	// do something
} catch ( SomeException5 se ) {
	// do something
}&lt;/pre&gt;

&lt;p&gt;OR&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;try
{

} catch ( SomeException1, SomeException2, SomeException3, SomeException4 se ) { 
	// do something
} catch ( SomeException5 se ) {
	// do something
}
 &lt;/pre&gt;

&lt;p&gt;I know, I know you think I have lost my mind.&amp;#160; But think about it.&amp;#160; There are times when you want to handle multiple exception types with the exact same logic.&amp;#160; However today when you do this you are forced to either create a helper method to handle the logic or repeat the logic over and over again.&amp;#160; If we had the ability to allow for fall through exceptions we could reduce duplicated code and reduce code noise.&lt;/p&gt;

&lt;p&gt;Now before you start asking questions like … let me provide some quick Q &amp;amp; A&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q)&lt;/strong&gt; If you do this you will never be able to know exactly what type of exception was thrown.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A)&lt;/strong&gt; You are correct, but in this scenario do you really care about the exception type?&amp;#160; If you did I am going to guess you would break it out into individual catch block&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q)&lt;/strong&gt; When would this situation actually be practical?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A)&lt;/strong&gt; Consider this.&amp;#160; You are creating a connection to a 3rd party resource (web service, wcf, api, etc) and that connection can throw a few different exceptions.&amp;#160; In some cases if the expected exception is throw you want to log and maybe roll back a transaction or something.&amp;#160; In this case i do not want to re-throw (or just let bubble up) the exception, but at the same time I do not want to duplicate my code.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So, let me have it.&amp;#160; Tell me how dumb this is.&lt;/p&gt;

&lt;p&gt;Tell next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55086" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/.Net/default.aspx">.Net</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Feedback/default.aspx">Feedback</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Opinion/default.aspx">Opinion</category></item><item><title>NHiberante and Join types in your mappings Select vs Join</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/11/nhiberante-and-join-types-in-your-mappings-select-vs-join.aspx</link><pubDate>Mon, 11 Jan 2010 20:34:30 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:54971</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=54971</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=54971</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/11/nhiberante-and-join-types-in-your-mappings-select-vs-join.aspx#comments</comments><description>&lt;p&gt;When you are setting up your NHibernate mappings you must pay close attention to the way you setup your relationships between your entities.&amp;#160; Recently I started profiling some of our statements and was shocked to see how some of them had a metric-crap ton of joins when they only needed one or two.&amp;#160; After a bit of looking I realized that we had explicitly set FetchType to .Join (via Fluent NHibernate) and this was a big no-no.&amp;#160; &lt;/p&gt;  &lt;p&gt;When you setup your associations to be join associations each time you use a entity you will get (for free :) ) the associations for that entity.&amp;#160; However, as you may guess this can be very, very expensive and not the desired outcome.&amp;#160; Below is how changing my FetchType from .Join to .Select (also, .Select is the default if you do not specify any FetchType).&lt;/p&gt;  &lt;p&gt;This is the SQL output when everything was setup for .Join&lt;/p&gt;  &lt;pre class="c#" name="code"&gt;FROM   RES_Basic this_
       inner join Res_Role roles1_
         on this_.RESOURCE_ID = roles1_.RESOURCE_ID
       left outer join O_BRANCH branch4_
         on roles1_.BRANCH_ID = branch4_.BRANCH_ID
       left outer join A_PROVIDER_TAXONOMY providerta5_
         on roles1_.TAXONOMY_ID = providerta5_.TAXONOMY_ID
       left outer join O_TEAM team6_
         on roles1_.TEAM_ID = team6_.TEAM_ID
       left outer join RES_Basic resource7_
         on roles1_.RESOURCE_ID = resource7_.RESOURCE_ID&lt;/pre&gt;

&lt;p&gt;This is the output after we changed to .Select (and setup my criteria to explicitly reference my Res_Role table)&lt;/p&gt;

&lt;pre class="c#" name="code"&gt;FROM   RES_Basic this_
       inner join Res_Role roles1_
         on this_.RESOURCE_ID = roles1_.RESOURCE_ID&lt;/pre&gt;

&lt;p&gt;As you can see, when I do it right I am only joining to the tables I want and this can lead to a huge performance savings.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=54971" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category></item><item><title>NHibernate and “The multi-part identifier … could not be bound” Exception</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/05/nhibernate-and-the-multi-part-identifier-could-not-be-bound-exception.aspx</link><pubDate>Tue, 05 Jan 2010 12:48:42 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:54916</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=54916</wfw:commentRss><wfw:comment>http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=54916</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/01/05/nhibernate-and-the-multi-part-identifier-could-not-be-bound-exception.aspx#comments</comments><description>&lt;p&gt;Today as I was creating a new NHibernate Criteria statement everything was working fine UNTIL I added the where clause.&amp;#160; At this point I started to get the following exception (which was seen via &lt;a href="http://nhprof.com/"&gt;NHibernate Profier&lt;/a&gt;).&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;WARN:      &lt;br /&gt;System.Data.SqlClient.SqlException: The multi-part identifier &amp;quot;doc2_.NAME&amp;quot; could not be bound.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;My criteria statement looked something like this&lt;/p&gt;  &lt;pre class="c#" name="code"&gt;var query = Session.CreateCriteria( typeof(DocumentSection), &amp;quot;docSection&amp;quot; )
    .CreateAlias( &amp;quot;docSection.DocumentSegment&amp;quot;, &amp;quot;docSegment&amp;quot;, JoinType.None )
    .CreateAlias( &amp;quot;docSegment.DocumentDefinition&amp;quot;, &amp;quot;doc&amp;quot;, JoinType.InnerJoin )
    .... MORE STUFF HERE

    .Add( Restrictions.Eq( &amp;quot;doc.Name&amp;quot;, documentName ) )

    .SetResultTransformer( new DistinctRootEntityResultTransformer() )
    .List();&lt;/pre&gt;

&lt;p&gt;When I first saw this error it did not make any sense as I KNEW that there was in fact a Name field on the object I was trying to hydrate.&amp;#160; But if you look closely at the first .CreateAlias you will notice the issue.&amp;#160; For my JoinType I had set it to &lt;font color="#ff0000"&gt;JoinType.None &lt;/font&gt;&lt;font color="#000000"&gt;and not &lt;font color="#ff0000"&gt;JoinType.Inner &lt;/font&gt; so when NHibernate wanted to hydrate my object it could not because as far as it was concerned the object was not meant to be hydrated.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;To resolve this issue I changed the JoinType to be Inner and all worked.&amp;#160; Below is the working code. &lt;/p&gt;

&lt;pre class="c#" name="code"&gt;var query = Session.CreateCriteria( typeof(DocumentSection), &amp;quot;docSection&amp;quot; )
    .CreateAlias( &amp;quot;docSection.DocumentSegment&amp;quot;, &amp;quot;docSegment&amp;quot;, JoinType.InnerJoin )
    .CreateAlias( &amp;quot;docSegment.DocumentDefinition&amp;quot;, &amp;quot;doc&amp;quot;, JoinType.InnerJoin )
    .... MORE STUFF HERE

    .Add( Restrictions.Eq( &amp;quot;doc.Name&amp;quot;, documentName ) )

    .SetResultTransformer( new DistinctRootEntityResultTransformer() )
    .List();&lt;/pre&gt;

&lt;p&gt;Till next time&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=54916" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category></item></channel></rss>
