<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>candland.code</title>
    <link>http://www.candland.net/blog/</link>
    <description />
    <language>en-us</language>
    <copyright>dusty candland</copyright>
    <lastBuildDate>Thu, 04 Mar 2010 11:29:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>candland@gmail.com</managingEditor>
    <webMaster>candland@gmail.com</webMaster>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Candlandcode" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="candlandcode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=87c4c2ba-84cd-4911-ad4c-c4c25373308a</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,87c4c2ba-84cd-4911-ad4c-c4c25373308a.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,87c4c2ba-84cd-4911-ad4c-c4c25373308a.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=87c4c2ba-84cd-4911-ad4c-c4c25373308a</wfw:commentRss>
      <slash:comments>2</slash:comments>
      
      <title>Resolve Lists and Arrays with Castle Windsor</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,87c4c2ba-84cd-4911-ad4c-c4c25373308a.aspx</guid>
      <link>http://www.candland.net/blog/2010/03/04/ResolveListsAndArraysWithCastleWindsor.aspx</link>
      <pubDate>Thu, 04 Mar 2010 11:29:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I’ve worked with the Castle Project for a long time, primarily with Windsor. However,&#xD;
I often forget there are Array and List dependencies resolvers build-in, but they&#xD;
need to be wired up. This is mostly for my memory and hopefully it helps someone else. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This sub resolvers are in this namespace;&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: anonymous pro; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;using&lt;/span&gt; Castle.MicroKernel.Resolvers.SpecializedResolvers;&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Before registering components, add the sub resolvers; &#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: anonymous pro; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
container.Kernel.Resolver.AddSubResolver(&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ArrayResolver&lt;/span&gt;(container.Kernel));&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
container.Kernel.Resolver.AddSubResolver(&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ListResolver&lt;/span&gt;(container.Kernel));&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Use like this, where there are multiple IService implementations that are needed by&#xD;
the DependsOnArrayOrList class.  &#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: anonymous pro; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;public&lt;/span&gt;&#xD;
            &lt;span style="color: blue"&gt;class&lt;/span&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;DependsOnArrayOrList&lt;/span&gt;&#xD;
          &lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt; DependsOnArrayOrList(&lt;span style="color: #2b91af"&gt;IService&lt;/span&gt;[]&#xD;
services)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt; DependsOnArrayOrList(&lt;span style="color: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;IService&lt;/span&gt;&amp;gt;&#xD;
services)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;public&lt;/span&gt;&#xD;
            &lt;span style="color: blue"&gt;interface&lt;/span&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;IService&lt;/span&gt;&#xD;
          &lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Not sure why these sub resolvers are not setup by default, but regardless they’re&#xD;
easy to setup and come in handy.&#xD;
&lt;/p&gt;&#xD;
        &lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&#xD;
          &lt;a href="http://digg.com/submit?url=http%3a%2f%2fwww.candland.net%2fblog%2f2010%2f03%2f04%2fResolveListsAndArraysWithCastleWindsor.aspx&amp;amp;title=Resolve+Lists+and+Arrays+with+Castle+Windsor"&gt;&#xD;
            &lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=87c4c2ba-84cd-4911-ad4c-c4c25373308a"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=52uidq86eCA:hXuyDqcFSjw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,87c4c2ba-84cd-4911-ad4c-c4c25373308a.aspx</comments>
      <category>castle</category>
    </item>
    <item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=559c13cd-b198-463d-95a9-3e34af3222e6</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,559c13cd-b198-463d-95a9-3e34af3222e6.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,559c13cd-b198-463d-95a9-3e34af3222e6.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=559c13cd-b198-463d-95a9-3e34af3222e6</wfw:commentRss>
      
      <title>Psake Builds and TeamCity Integration</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,559c13cd-b198-463d-95a9-3e34af3222e6.aspx</guid>
      <link>http://www.candland.net/blog/2010/02/08/PsakeBuildsAndTeamCityIntegration.aspx</link>
      <pubDate>Mon, 08 Feb 2010 11:36:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://code.google.com/p/psake/"&gt;Psake&lt;/a&gt; is a powerful build system, build&#xD;
on Powershell for a lot of functionality and familiarity. And &lt;a href="http://www.jetbrains.com/teamcity/"&gt;TeamCity&lt;/a&gt; is&#xD;
a really nice continuous integration server, checkout the &lt;a href="http://teamcity.codebetter.com/login.html"&gt;CodeBetter&#xD;
TeamCity&lt;/a&gt; install for a good demo. Hooking the two up was not a easy as using just&#xD;
Msbuild or Nant, but it’s not really too bad. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
First, your Psake script needs to check the exit codes of the applications it calls.&#xD;
This is important to do regardless because Powershell doesn’t error out based on the&#xD;
exit code. The &lt;a href="http://github.com/JamesKovacs/psake"&gt;trunk version&lt;/a&gt; of&#xD;
Psake has a convenience function to execute a command and check it’s exit code is&#xD;
greater than 0, called exec:&#xD;
&lt;/p&gt;&#xD;
        &lt;code&gt;&#xD;
          &lt;pre&gt;task Compile -depends Clean { &#xD;
    exec {msbuild $sln_file /p:configuration=$configuration} &#xD;
}&lt;/pre&gt;&#xD;
        &lt;/code&gt;&#xD;
        &lt;p&gt;&#xD;
You can also pass a message as the second argument. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
With this checking in place, next is a bat script to use from the TeamCity command&#xD;
line build option.&#xD;
&lt;/p&gt;&#xD;
        &lt;code&gt;@echo off&lt;br&gt;&#xD;
powershell -NoProfile -ExecutionPolicy unrestricted -Command "&amp;amp; {Import-Module&#xD;
'.\tools\psake\psake.psm1'; invoke-psake -t %1; if ($Error -ne '') {write-host "ERROR:&#xD;
$error" -fore RED; exit $error.Count} }"&lt;/code&gt;&#xD;
        &lt;p&gt;&#xD;
This executes a Powershell prompt which imports the Psake module and then calls the&#xD;
provided Psake task. Finally, it checks the $Error variable and sets the exit code&#xD;
to the number of errors returned by the script. This will fail the TeamCity build&#xD;
and allows any error thrown by Powershell to break the build. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Last is to have TeamCity run the bat file with the desired target. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
psake.bat Compile&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
One thing to note is that some things return exit code other then 0 but that are not&#xD;
errors. In that case you can check the Powershell variable $LastExitCode and throw&#xD;
errors based on that.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Thanks to the &lt;a href="http://groups.google.com/group/psake-users"&gt;psake users group&lt;/a&gt; for&#xD;
all their help!&#xD;
&lt;/p&gt;&#xD;
        &lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&#xD;
          &lt;a href="http://digg.com/submit?url=http%3a%2f%2fwww.candland.net%2fblog%2f2010%2f02%2f08%2fPsakeBuilsAndTeamCityIntegration.aspx&amp;amp;title=Psake+Builds+and+TeamCity+Integration"&gt;&#xD;
            &lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=559c13cd-b198-463d-95a9-3e34af3222e6"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=5xnTjJz2rmM:Zh7v-ZJ6-bc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,559c13cd-b198-463d-95a9-3e34af3222e6.aspx</comments>
      <category>build</category>
      <category>powershell</category>
      <category>psake</category>
      <category>teamcity</category>
    </item>
    <item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=12ef27e8-e6f9-4077-9c20-afc4e7450223</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,12ef27e8-e6f9-4077-9c20-afc4e7450223.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,12ef27e8-e6f9-4077-9c20-afc4e7450223.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=12ef27e8-e6f9-4077-9c20-afc4e7450223</wfw:commentRss>
      
      <title>error CS1668: Warning as Error: Invalid search path 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib' specified in 'LIB environment variable'</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,12ef27e8-e6f9-4077-9c20-afc4e7450223.aspx</guid>
      <link>http://www.candland.net/blog/2010/01/30/errorCS1668WarningAsErrorInvalidSearchPathCProgramFilesMicrosoftSDKsWindowsv60AlibSpecifiedInLIBEnvironmentVariable.aspx</link>
      <pubDate>Sat, 30 Jan 2010 10:32:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I’m not sure what caused my setup to produce this error, but after searching for a&#xD;
while and not finding any reason, I just added the lib directory and all was good.&#xD;
I was getting this when doing command line compiles and when using the spark view&#xD;
engine. I hope this might save me or someone else some time in the future.&#xD;
&lt;/p&gt;&#xD;
        &lt;blockquote&gt;&#xD;
          &lt;p&gt;&#xD;
error CS1668: Warning as Error: Invalid search path 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib'&#xD;
specified in 'LIB environment variable'&#xD;
&lt;/p&gt;&#xD;
        &lt;/blockquote&gt;&#xD;
        &lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&#xD;
          &lt;a href="http://digg.com/submit?url=http%3a%2f%2fwww.candland.net%2fblog%2f2010%2f01%2f30%2ferrorCS1668WarningAsErrorInvalidSearchPathCProgramFilesMicrosoftSDKsWindowsv60AlibSpecifiedInLIBEnvironmentVariable.aspx&amp;amp;title=error+CS1668%3a+Warning+as+Error%3a+Invalid+search+path+'C%3a%5cProgram+Files%5cMicrosoft+SDKs%5cWindows%5cv6.0A%5clib'+specified+in+'LIB+environment+variable'"&gt;&#xD;
            &lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=12ef27e8-e6f9-4077-9c20-afc4e7450223"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=6qkKvaqtlf8:8v5xPbmbtyA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,12ef27e8-e6f9-4077-9c20-afc4e7450223.aspx</comments>
      <category>build</category>
      <category>csharp</category>
      <category>spark</category>
    </item>
    <item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=64063524-1e1c-49cf-96a0-7fbd24ad73c6</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,64063524-1e1c-49cf-96a0-7fbd24ad73c6.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,64063524-1e1c-49cf-96a0-7fbd24ad73c6.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=64063524-1e1c-49cf-96a0-7fbd24ad73c6</wfw:commentRss>
      <slash:comments>1</slash:comments>
      
      <title>A New Year &amp;amp; A New Venture: Red27 Consulting</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,64063524-1e1c-49cf-96a0-7fbd24ad73c6.aspx</guid>
      <link>http://www.candland.net/blog/2010/01/21/ANewYearAmpANewVentureRed27Consulting.aspx</link>
      <pubDate>Thu, 21 Jan 2010 21:54:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://www.candland.net/blog/content/binary/WindowsLiveWriter/2d2470669370_107D5/business-card-front_2.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; margin: 0px auto 10px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="business-card-front" border="0" alt="business-card-front" src="http://www.candland.net/blog/content/binary/WindowsLiveWriter/2d2470669370_107D5/business-card-front_thumb.png" width="359" height="210"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;I’ve&#xD;
decided to take the plunge and start consulting full time. My company, &lt;a href="http://www.red27.net"&gt;Red27&#xD;
Consulting&lt;/a&gt;, has been around for few years, but this year I will be pursuing consulting/independent&#xD;
development work full time. Red27 will be an agile/alt.net/craftsmanship based business,&#xD;
building websites and web applications. We will partner with customers to build what&#xD;
they need quickly and with high quality. The challenge is how to show the value in&#xD;
these agile/alt.net/craftsmanship processes and principles to people not in software&#xD;
development. I believe, over time, using these processes and principles will prove&#xD;
to be a better way to build software. I will write about these experiences here along&#xD;
with the technical content that I’ve been writing.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Lastly, keep &lt;a href="http://www.red27.net"&gt;Red27 Consulting&lt;/a&gt; in mind when someone&#xD;
has a website or web application they want built!&#xD;
&lt;/p&gt;&#xD;
        &lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&#xD;
          &lt;a href="http://digg.com/submit?url=http%3a%2f%2fwww.candland.net%2fblog%2f2010%2f01%2f21%2fANewYearAmpANewVentureRed27Consulting.aspx&amp;amp;title=A+New+Year+%26+A+New+Venture%3a+Red27+Consulting"&gt;&#xD;
            &lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=64063524-1e1c-49cf-96a0-7fbd24ad73c6"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=_2vcwJOoKdo:OFlElHirEa8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,64063524-1e1c-49cf-96a0-7fbd24ad73c6.aspx</comments>
      <category>consulting</category>
      <category>red27</category>
    </item>
    <item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=dca10fe1-b0cc-41b9-a34d-39338f908dd3</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,dca10fe1-b0cc-41b9-a34d-39338f908dd3.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,dca10fe1-b0cc-41b9-a34d-39338f908dd3.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=dca10fe1-b0cc-41b9-a34d-39338f908dd3</wfw:commentRss>
      
      <title>Making Sure A NHibernate IInterceptor Is In The Session</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,dca10fe1-b0cc-41b9-a34d-39338f908dd3.aspx</guid>
      <link>http://www.candland.net/blog/2010/01/10/MakingSureANHibernateIInterceptorIsInTheSession.aspx</link>
      <pubDate>Sun, 10 Jan 2010 03:24:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
Building on the previous post &lt;a href="http://www.candland.net/blog/2010/01/09/InterceptingNHibernateToHandleAdditionalDatabaseWork.aspx"&gt;Intercepting&#xD;
NHibernate to Handle Additional Database Work&lt;/a&gt;, I used the ILifecycle interface&#xD;
to ensure the IInterceptor was setup on the session before saving MyEntity. I ILifecycle&#xD;
interface is deprecated, but I needed some way to make sure the interceptor was there.&#xD;
If an entity has the ILifecycle interface nothing more is needed, NHibernate will&#xD;
call the methods. I used the OnSave method, to inspect the session instance and throw&#xD;
and exception if needed. Anyway, here’s the code:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 9pt; background: white; color: black; font-family: anonymous pro, courier new, monospace"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;public&lt;/span&gt;&#xD;
            &lt;span style="color: blue"&gt;class&lt;/span&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;MyEntity&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;ILifecycle&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;virtual&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt; Id&#xD;
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;virtual&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt; ParentId&#xD;
{ &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;virtual&lt;/span&gt;&lt;span style="color: #2b91af"&gt;LifecycleVeto&lt;/span&gt; OnSave(&lt;span style="color: #2b91af"&gt;ISession&lt;/span&gt; s)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;var&lt;/span&gt; sessionDelegate&#xD;
= s &lt;span style="color: blue"&gt;as&lt;/span&gt;&lt;span style="color: #2b91af"&gt;SessionDelegate&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;var&lt;/span&gt; session&#xD;
= sessionDelegate != &lt;span style="color: blue"&gt;null&lt;/span&gt; ? sessionDelegate.InnerSession &lt;span style="color: blue"&gt;as&lt;/span&gt;&lt;span style="color: #2b91af"&gt;SessionImpl&lt;/span&gt; :&#xD;
s &lt;span style="color: blue"&gt;as&lt;/span&gt;&lt;span style="color: #2b91af"&gt;SessionImpl&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;if&lt;/span&gt; (session&#xD;
!= &lt;span style="color: blue"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; session.Interceptor.GetType().Equals(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;MyEntityInterceptor&lt;/span&gt;)))&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: #2b91af"&gt;LifecycleVeto&lt;/span&gt;.NoVeto;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;throw&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ApplicationException&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"MyEntityInterceptor&#xD;
needs to be registered with the container."&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;virtual&lt;/span&gt;&lt;span style="color: #2b91af"&gt;LifecycleVeto&lt;/span&gt; OnUpdate(&lt;span style="color: #2b91af"&gt;ISession&lt;/span&gt; s)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: #2b91af"&gt;LifecycleVeto&lt;/span&gt;.NoVeto;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;virtual&lt;/span&gt;&lt;span style="color: #2b91af"&gt;LifecycleVeto&lt;/span&gt; OnDelete(&lt;span style="color: #2b91af"&gt;ISession&lt;/span&gt; s)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: #2b91af"&gt;LifecycleVeto&lt;/span&gt;.NoVeto;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;virtual&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; OnLoad(&lt;span style="color: #2b91af"&gt;ISession&lt;/span&gt; s, &lt;span style="color: blue"&gt;object&lt;/span&gt; id)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
I think there are potentially better ways to handle this, but with the existing constraints&#xD;
on the code and time work something out, this was the way I went.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=dca10fe1-b0cc-41b9-a34d-39338f908dd3"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=W6O8jrI_C6M:iFEcx42OvnU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,dca10fe1-b0cc-41b9-a34d-39338f908dd3.aspx</comments>
      <category>csharp</category>
      <category>nhibernate</category>
    </item>
    <item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=3033c63f-9723-416f-a994-f067b3d63d1c</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,3033c63f-9723-416f-a994-f067b3d63d1c.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,3033c63f-9723-416f-a994-f067b3d63d1c.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=3033c63f-9723-416f-a994-f067b3d63d1c</wfw:commentRss>
      
      <title>Intercepting NHibernate to Handle Additional Database Work</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,3033c63f-9723-416f-a994-f067b3d63d1c.aspx</guid>
      <link>http://www.candland.net/blog/2010/01/09/InterceptingNHibernateToHandleAdditionalDatabaseWork.aspx</link>
      <pubDate>Sat, 09 Jan 2010 03:13:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p style="margin: 0px"&gt;&#xD;
Today I needed to take addition database action when an entity is saved or deleted.&#xD;
A trigger might have been an option, but I try to limit the use of triggers. NHibernate&#xD;
to the rescue! Since the code was already using NHibernate it was an easy choice.&#xD;
There are a couple of options here. First is to use a stored procedure for the insert.&#xD;
However, that requires not using identity columns and wouldn’t work in this case.&#xD;
There is the ILifecycle interface, but it is deprecated and doesn’t have after-save&#xD;
hooks. Which leaves the IInterceptor interface.&#xD;
&lt;/p&gt;&#xD;
        &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p style="margin: 0px"&gt;&#xD;
Sub-classing EmptyInterceptor, I overrode the needed methods. If the entity is the&#xD;
one I’m concerned with, I store it or it’s data for later use in a queue collection.&#xD;
In the PostFlush method the entities stored in the queue will have their Identity&#xD;
set and can be used to set the properties for the additional work. Also, the deleted&#xD;
object will have been deleted which is important. I’m not sure I needed lock the queue&#xD;
objects, but I guess there is a change the session could be used on multiple threads&#xD;
and to be save they are locked. &#xD;
&lt;/p&gt;&#xD;
        &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;p style="margin: 0px"&gt;&#xD;
The named queries are stored in the MyEntity Mapping file using the sql-query element.&#xD;
&lt;/p&gt;&#xD;
        &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 9pt; background: white; color: black; font-family: anonymous pro, courier new, monospace"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;public&lt;/span&gt;&#xD;
            &lt;span style="color: blue"&gt;class&lt;/span&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;MyEntityInterceptor&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;EmptyInterceptor&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ISession&lt;/span&gt; _session;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: blue"&gt;readonly&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Queue&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;MyEntity&lt;/span&gt;&amp;gt;&#xD;
_saves = &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Queue&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;MyEntity&lt;/span&gt;&amp;gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: blue"&gt;readonly&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Queue&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;&#xD;
_deletes = &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Queue&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;override&lt;/span&gt;&lt;span style="color: blue"&gt;bool&lt;/span&gt; OnSave(&lt;span style="color: blue"&gt;object&lt;/span&gt; entity, &lt;span style="color: blue"&gt;object&lt;/span&gt; id, &lt;span style="color: blue"&gt;object&lt;/span&gt;[]&#xD;
state, &lt;span style="color: blue"&gt;string&lt;/span&gt;[] propertyNames, &lt;span style="color: blue"&gt;global&lt;/span&gt;::NHibernate.Type.&lt;span style="color: #2b91af"&gt;IType&lt;/span&gt;[]&#xD;
types)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;var&lt;/span&gt; myEntity&#xD;
= entity &lt;span style="color: blue"&gt;as&lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyEntity&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;if&lt;/span&gt; (myEntity&#xD;
!= &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            _saves.Enqueue(myEntity);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;override&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; OnDelete(&lt;span style="color: blue"&gt;object&lt;/span&gt; entity, &lt;span style="color: blue"&gt;object&lt;/span&gt; id, &lt;span style="color: blue"&gt;object&lt;/span&gt;[]&#xD;
state, &lt;span style="color: blue"&gt;string&lt;/span&gt;[] propertyNames, &lt;span style="color: blue"&gt;global&lt;/span&gt;::NHibernate.Type.&lt;span style="color: #2b91af"&gt;IType&lt;/span&gt;[]&#xD;
types)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;var&lt;/span&gt; myEntity&#xD;
= entity &lt;span style="color: blue"&gt;as&lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyEntity&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;if&lt;/span&gt; (myEntity&#xD;
!= &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;lock&lt;/span&gt; (_deletes)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                &lt;span style="color: blue"&gt;if&lt;/span&gt; (!_deletes.Contains(myEntity.ParentId))&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                   &#xD;
_deletes.Enqueue(myEntity.ParentId);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;override&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; PostFlush(&lt;span style="color: #2b91af"&gt;ICollection&lt;/span&gt; entities)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        ExecuteSaves();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        ExecuteDeletes();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; ExecuteSaves()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;lock&lt;/span&gt; (_saves)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;while&lt;/span&gt; (_saves.Count&#xD;
&amp;gt; 0)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                &lt;span style="color: blue"&gt;var&lt;/span&gt; myEntity&#xD;
= _saves.Dequeue();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
_session.GetNamedQuery(&lt;span style="color: #a31515"&gt;"SqlToExecuteForSaves"&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                   &#xD;
.SetInt32(&lt;span style="color: #a31515"&gt;"Id"&lt;/span&gt;, myEntity.Id)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                   &#xD;
.ExecuteUpdate();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; ExecuteDeletes()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;lock&lt;/span&gt; (_deletes)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;while&lt;/span&gt; (_deletes.Count&#xD;
&amp;gt; 0)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                &lt;span style="color: blue"&gt;var&lt;/span&gt; id&#xD;
= _deletes.Dequeue();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
_session.GetNamedQuery(&lt;span style="color: #a31515"&gt;"SqlToExecuteForDeletes"&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                   &#xD;
.SetInt32(&lt;span style="color: #a31515"&gt;"Id"&lt;/span&gt;, id)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                   &#xD;
.ExecuteUpdate();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;override&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; SetSession(&lt;span style="color: #2b91af"&gt;ISession&lt;/span&gt; session)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        _session = session;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;public&lt;/span&gt;&#xD;
            &lt;span style="color: blue"&gt;class&lt;/span&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;MyEntity&lt;/span&gt;&#xD;
          &lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt; ParentId;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt; Id;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Since it’s using the ISession and IQuery interface, unit testing was easy.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The code is also using the NHibernateFacility from the CastleProject. Which makes&#xD;
adding interceptors as easy as adding them to the container. The naming is important&#xD;
as that’s how the facility looks up the interceptors. The first will be used for all&#xD;
session factories unless there is on for the specific factory as the second option&#xD;
shows.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 9pt; background: white; color: black; font-family: anonymous pro, courier new, monospace"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
container.Register(&lt;span style="color: #2b91af"&gt;Component&lt;/span&gt;.For&amp;lt;&lt;span style="color: #2b91af"&gt;IInterceptor&lt;/span&gt;&amp;gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    .ImplementedBy&amp;lt;&lt;span style="color: #2b91af"&gt;MyEntityInterceptor&lt;/span&gt;&amp;gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    .Named(&lt;span style="color: #a31515"&gt;"nhibernate.session.interceptor"&lt;/span&gt;));&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
container.Register(&lt;span style="color: #2b91af"&gt;Component&lt;/span&gt;.For&amp;lt;&lt;span style="color: #2b91af"&gt;IInterceptor&lt;/span&gt;&amp;gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    .ImplementedBy&amp;lt;&lt;span style="color: #2b91af"&gt;MyEntityInterceptor&lt;/span&gt;&amp;gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    .Named(&lt;span style="color: #a31515"&gt;"nhibernate.session.interceptor.MyOtherFactoryAlias"&lt;/span&gt;));&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=3033c63f-9723-416f-a994-f067b3d63d1c"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=3Q_KxsHbIZI:JkgsBWaxGLc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,3033c63f-9723-416f-a994-f067b3d63d1c.aspx</comments>
      <category>castle</category>
      <category>csharp</category>
      <category>nhibernate</category>
    </item>
    <item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=0e26b00a-110b-419d-9912-2d90b47138ea</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,0e26b00a-110b-419d-9912-2d90b47138ea.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,0e26b00a-110b-419d-9912-2d90b47138ea.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=0e26b00a-110b-419d-9912-2d90b47138ea</wfw:commentRss>
      
      <title>N2CMS Build From Source</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,0e26b00a-110b-419d-9912-2d90b47138ea.aspx</guid>
      <link>http://www.candland.net/blog/2009/12/22/N2CMSBuildFromSource.aspx</link>
      <pubDate>Tue, 22 Dec 2009 08:46:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://www.candland.net/blog/content/binary/WindowsLiveWriter/N2CMSBuildFromSource_10807/image_2.png"&gt;&#xD;
            &lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://www.candland.net/blog/content/binary/WindowsLiveWriter/N2CMSBuildFromSource_10807/image_thumb.png" width="468" height="251"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;ol&gt;&#xD;
          &lt;li&gt;&#xD;
Download source &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Run Prepare_Dependencies-vs2008.bat &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Deploy_Everything-vs2008.bat &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Copy the output/Templates_Mvc directory to a new directory for the projects &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Edit permissions on the wwwroot sub folder to add IIS_USERS if needed. &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
x64 only: download &lt;a href="http://sourceforge.net/projects/sqlite-dotnet2/files/"&gt;SQLite&lt;/a&gt; and&#xD;
copy the x64 version of System.Data.SQLite.dll to wwwroot\bin &#xD;
&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Follow the instructions in the install.txt &#xD;
&lt;/li&gt;&#xD;
        &lt;/ol&gt;&#xD;
        &lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&#xD;
          &lt;a href="http://digg.com/submit?url=http%3a%2f%2fwww.candland.net%2fblog%2f2009%2f12%2f22%2fN2CMSBuildFromSource.aspx&amp;amp;title=N2CMS+Build+From+Source"&gt;&#xD;
            &lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=0e26b00a-110b-419d-9912-2d90b47138ea"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=OTGkZcjQgKk:FZgZdB7nC9Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,0e26b00a-110b-419d-9912-2d90b47138ea.aspx</comments>
      <category>n2cms</category>
    </item>
    <item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=fd8e11f2-5fa7-4b25-9241-140a5e5ef5b1</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,fd8e11f2-5fa7-4b25-9241-140a5e5ef5b1.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,fd8e11f2-5fa7-4b25-9241-140a5e5ef5b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=fd8e11f2-5fa7-4b25-9241-140a5e5ef5b1</wfw:commentRss>
      
      <title>FluentNHibernate Many-To-Many Mapping</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,fd8e11f2-5fa7-4b25-9241-140a5e5ef5b1.aspx</guid>
      <link>http://www.candland.net/blog/2009/12/14/FluentNHibernateManyToManyMapping.aspx</link>
      <pubDate>Mon, 14 Dec 2009 08:32:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
Explained here &lt;a href="http://hackingon.net/post/Many-to-Many-Relationships-With-Fluent-NHibernate-Automapping.aspx"&gt;Hackingon.net:&#xD;
Many-to-Many Relationships With Fluent NHibernate Automapping&lt;/a&gt;&lt;/p&gt;&#xD;
        &lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&#xD;
          &lt;a href="http://digg.com/submit?url=http%3a%2f%2fwww.candland.net%2fblog%2f2009%2f12%2f14%2fFluentNHibernateManyToManyMapping.aspx&amp;amp;title=FluentNHibernate+Many-To-Many+Mapping"&gt;&#xD;
            &lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=fd8e11f2-5fa7-4b25-9241-140a5e5ef5b1"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=x9ivcaiBhu0:rqpnlt-HP4c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,fd8e11f2-5fa7-4b25-9241-140a5e5ef5b1.aspx</comments>
      <category>fluentnhibernate</category>
    </item>
    <item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=84540f41-a022-40b3-ba68-efe68b2acb8d</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,84540f41-a022-40b3-ba68-efe68b2acb8d.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,84540f41-a022-40b3-ba68-efe68b2acb8d.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=84540f41-a022-40b3-ba68-efe68b2acb8d</wfw:commentRss>
      
      <title>Automating Releases with SFTP</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,84540f41-a022-40b3-ba68-efe68b2acb8d.aspx</guid>
      <link>http://www.candland.net/blog/2009/12/10/AutomatingReleasesWithSFTP.aspx</link>
      <pubDate>Thu, 10 Dec 2009 23:32:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I’m trying to automate the deployment process for a website. I’m using &lt;a href="http://code.google.com/p/psake/"&gt;Psake&lt;/a&gt; for&#xD;
the build process and &lt;a href="http://code.google.com/p/migratordotnet/"&gt;Migrator.Net&lt;/a&gt; for&#xD;
the db migrations. Which left the problem of getting the code to the server. I’ve&#xD;
taken a stab that this using this &lt;a href="http://www.teamhackaday.com/2008/04/23/securing-windows-remote-desktop-with-copssh/"&gt;guide&lt;/a&gt; to&#xD;
setup SFTP with a restricted user with just SFTP access using public/private keys. &#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Next was to automate the file upload, first I just used at batch file and psftp.exe,&#xD;
this worked except it re-uploads everything, much of which didn’t change. So, next&#xD;
was FileZilla, no luck there. Finally, &lt;a href="http://winscp.net/eng/download.php"&gt;WinSCP&lt;/a&gt; which&#xD;
works ok, but it doesn’t seem to allow a fully automated sync of files, but it does&#xD;
get close. &#xD;
&lt;/p&gt;&#xD;
        &lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&#xD;
          &lt;a href="http://digg.com/submit?url=http%3a%2f%2fwww.candland.net%2fblog%2f2009%2f12%2f10%2fAutomatingReleasesWithSFTP.aspx&amp;amp;title=Automating+Releases+with+SFTP"&gt;&#xD;
            &lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=84540f41-a022-40b3-ba68-efe68b2acb8d"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=vLtRBjPe_mw:VQ-EOM2drbk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,84540f41-a022-40b3-ba68-efe68b2acb8d.aspx</comments>
      <category>build</category>
      <category>psake</category>
      <category>sftp</category>
    </item>
    <item>
      <trackback:ping>http://www.candland.net/blog/Trackback.aspx?guid=8f472b65-9409-4d33-94d2-3812b2f9eb68</trackback:ping>
      <pingback:server>http://www.candland.net/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.candland.net/blog/PermaLink,guid,8f472b65-9409-4d33-94d2-3812b2f9eb68.aspx</pingback:target>
      <dc:creator>Dusty Candland</dc:creator>
      <wfw:comment>http://www.candland.net/blog/CommentView,guid,8f472b65-9409-4d33-94d2-3812b2f9eb68.aspx</wfw:comment>
      <wfw:commentRss>http://www.candland.net/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=8f472b65-9409-4d33-94d2-3812b2f9eb68</wfw:commentRss>
      
      <title>Asp.Net MVC CheckBoxList HtmlHelper Extension</title>
      <guid isPermaLink="false">http://www.candland.net/blog/PermaLink,guid,8f472b65-9409-4d33-94d2-3812b2f9eb68.aspx</guid>
      <link>http://www.candland.net/blog/2009/11/27/AspNetMVCCheckBoxListHtmlHelperExtension.aspx</link>
      <pubDate>Fri, 27 Nov 2009 01:32:00 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I added some more methods to the code provided by Tyler Garlick’s &lt;a href="http://blog.tylergarlick.com/index.php/2009/03/checkboxlist-for-aspnet-mvc/"&gt;CheckBoxList&#xD;
for ASP.net MVC&lt;/a&gt; to allow a dictionary to be passed in place of a list of SelectListItems&#xD;
and an optional list of selected ids. Anyway, here’s the full class.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: anonymous pro; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;using&lt;/span&gt; System.Collections.Generic;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;using&lt;/span&gt; System.Linq;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;using&lt;/span&gt; System.Text;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;namespace&lt;/span&gt; System.Web.Mvc&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;CheckBoxListHelper&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; CheckBoxList(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;HtmlHelper&lt;/span&gt; helper, &lt;span style="color: blue"&gt;string&lt;/span&gt; name, &lt;span style="color: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
items)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt; CheckBoxList(helper,&#xD;
name, items, &lt;span style="color: blue"&gt;null&lt;/span&gt;, &lt;span style="color: blue"&gt;null&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; CheckBoxList(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;HtmlHelper&lt;/span&gt; helper, &lt;span style="color: blue"&gt;string&lt;/span&gt; name, &lt;span style="color: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
items, &lt;span style="color: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: blue"&gt;object&lt;/span&gt;&amp;gt;&#xD;
checkboxHtmlAttributes)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt; CheckBoxList(helper,&#xD;
name, items, &lt;span style="color: blue"&gt;null&lt;/span&gt;, checkboxHtmlAttributes);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; CheckBoxList(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;HtmlHelper&lt;/span&gt; helper, &lt;span style="color: blue"&gt;string&lt;/span&gt; name, &lt;span style="color: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
items, &lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
selectedValues)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt; CheckBoxList(helper,&#xD;
name, items, selectedValues, &lt;span style="color: blue"&gt;null&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; CheckBoxList(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;HtmlHelper&lt;/span&gt; helper, &lt;span style="color: blue"&gt;string&lt;/span&gt; name, &lt;span style="color: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
items, &lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;&#xD;
selectedValues, &lt;span style="color: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: blue"&gt;object&lt;/span&gt;&amp;gt;&#xD;
checkboxHtmlAttributes)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;var&lt;/span&gt; selectListItems&#xD;
= &lt;span style="color: blue"&gt;from&lt;/span&gt; i &lt;span style="color: blue"&gt;in&lt;/span&gt; items&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                                  &lt;span style="color: blue"&gt;select&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;SelectListItem&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                                            &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                                                &#xD;
Text = i.Key,&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                                                &#xD;
Value = i.Value,&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                                                &#xD;
Selected = (selectedValues != &lt;span style="color: blue"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; selectedValues.Contains(i.Value))&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                                            &#xD;
};&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt; CheckBoxList(helper,&#xD;
name, selectListItems, checkboxHtmlAttributes);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; CheckBoxList(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;HtmlHelper&lt;/span&gt; helper, &lt;span style="color: blue"&gt;string&lt;/span&gt; name, &lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;SelectListItem&lt;/span&gt;&amp;gt;&#xD;
items)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt; CheckBoxList(helper,&#xD;
name, items, &lt;span style="color: blue"&gt;null&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; CheckBoxList(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;HtmlHelper&lt;/span&gt; helper, &lt;span style="color: blue"&gt;string&lt;/span&gt; name, &lt;span style="color: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;SelectListItem&lt;/span&gt;&amp;gt;&#xD;
items, &lt;span style="color: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;, &lt;span style="color: blue"&gt;object&lt;/span&gt;&amp;gt;&#xD;
checkboxHtmlAttributes)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;var&lt;/span&gt; output&#xD;
= &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;StringBuilder&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;foreach&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; item &lt;span style="color: blue"&gt;in&lt;/span&gt; items)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
output.Append(&lt;span style="color: #a31515"&gt;"&amp;lt;div class=\"fields\"&amp;gt;&amp;lt;label&amp;gt;"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                &lt;span style="color: blue"&gt;var&lt;/span&gt; checkboxList&#xD;
= &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;TagBuilder&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"input"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
checkboxList.MergeAttribute(&lt;span style="color: #a31515"&gt;"type"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"checkbox"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
checkboxList.MergeAttribute(&lt;span style="color: #a31515"&gt;"name"&lt;/span&gt;,&#xD;
name);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
checkboxList.MergeAttribute(&lt;span style="color: #a31515"&gt;"value"&lt;/span&gt;,&#xD;
item.Value);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                &lt;span style="color: green"&gt;//&#xD;
Check to see if it's checked&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                &lt;span style="color: blue"&gt;if&lt;/span&gt; (item.Selected)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                   &#xD;
checkboxList.MergeAttribute(&lt;span style="color: #a31515"&gt;"checked"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"checked"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                &lt;span style="color: green"&gt;//&#xD;
Add any attributes&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                &lt;span style="color: blue"&gt;if&lt;/span&gt; (checkboxHtmlAttributes&#xD;
!= &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                   &#xD;
checkboxList.MergeAttributes(checkboxHtmlAttributes);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
checkboxList.SetInnerText(item.Text);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
output.Append(checkboxList.ToString(&lt;span style="color: #2b91af"&gt;TagRenderMode&lt;/span&gt;.SelfClosing));&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
output.Append(&lt;span style="color: #a31515"&gt;"&amp;amp;nbsp; "&lt;/span&gt; + item.Text&#xD;
+ &lt;span style="color: #a31515"&gt;"&amp;lt;/label&amp;gt;&amp;lt;/div&amp;gt;"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt; output.ToString();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
}&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
On the view you can pass a dictionary made from items in your view model and selected&#xD;
values form your view model. &#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: anonymous pro; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&#xD;
            &lt;span style="color: maroon"&gt;div&lt;/span&gt;&#xD;
            &lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&#xD;
          &lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: teal"&gt;${&lt;/span&gt;Html.CheckBoxList(&lt;span style="color: #a31515"&gt;"Product.Categories"&lt;/span&gt;,&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
      ViewData.Model.Categories.ToDictionary(c =&amp;gt; c.Name,&#xD;
c =&amp;gt; c.Id.ToString()), &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
      ViewData.Model.Product.Categories.Select(c =&amp;gt; c.Id.ToString()))&lt;span style="color: teal"&gt;}&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&#xD;
            &lt;span style="color: maroon"&gt;div&lt;/span&gt;&#xD;
            &lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&#xD;
          &lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
In the controller you can access the form values in the request as a comma list of&#xD;
values by the name of the form field.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: anonymous pro; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
Request.Form[&lt;span style="color: #a31515"&gt;"Product.Categories"&lt;/span&gt;]&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Hope this helps and thanks to Tyler Garlick for meat of the code.&#xD;
&lt;/p&gt;&#xD;
        &lt;div class="wlWriterHeaderFooter" style="text-align:right; margin:0px; padding:4px 0px 4px 0px;"&gt;&#xD;
          &lt;a href="http://digg.com/submit?url=http%3a%2f%2fwww.candland.net%2fblog%2f2009%2f11%2f27%2fAspNetMVCCheckBoxListHtmlHelperExtension.aspx&amp;amp;title=Asp.Net+MVC+CheckBoxList+HtmlHelper+Extension"&gt;&#xD;
            &lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border: 0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.candland.net/blog/aggbug.ashx?id=8f472b65-9409-4d33-94d2-3812b2f9eb68"&gt;&lt;/img&gt;&#xD;
      &lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/Candlandcode?a=kdoQPu3DuVI:Pa8mBxZr4zA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/Candlandcode?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description>
      <comments>http://www.candland.net/blog/CommentView,guid,8f472b65-9409-4d33-94d2-3812b2f9eb68.aspx</comments>
      <category>asp.net</category>
      <category>mvc</category>
    </item>
  </channel>
</rss>
