<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Patrick Steele&amp;#39;s .NET Blog</title><link>http://weblogs.asp.net/psteele/default.aspx</link><description>Implements ICodeWithDotNet</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/dotnetmvp" type="application/rss+xml" /><item><title>Displaying an image from a database in MonoRail</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/451391587/displaying-an-image-from-a-database-in-monorail.aspx</link><pubDate>Thu, 13 Nov 2008 03:28:27 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6732400</guid><dc:creator>PSteele</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/11/12/displaying-an-image-from-a-database-in-monorail.aspx#comments</comments><description>&lt;p&gt;Sometimes, it's just too easy!&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href="http://gabriel-schenker.blogspot.com/2008/11/how-to-display-image-retrieved-from-db.html"&gt;How to display an image retrieved from DB in Monorail&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0951083c-c181-45fe-9b3a-0da53de28f92" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/Castle" rel="tag"&gt;Castle&lt;/a&gt;, &lt;a href="http://technorati.com/tags/MonoRail" rel="tag"&gt;MonoRail&lt;/a&gt;, &lt;a href="http://technorati.com/tags/MVC" rel="tag"&gt;MVC&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6732400" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/451391587" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psteele/archive/tags/MonoRail/default.aspx">MonoRail</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/11/12/displaying-an-image-from-a-database-in-monorail.aspx</feedburner:origLink></item><item><title>ActiveRecord: Never forget there's a database</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/444438450/activerecord-never-forget-there-s-a-database.aspx</link><pubDate>Thu, 06 Nov 2008 14:44:30 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6723571</guid><dc:creator>PSteele</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/11/06/activerecord-never-forget-there-s-a-database.aspx#comments</comments><description>&lt;p&gt;Some lessons learned while using &lt;a href="http://www.castleproject.org/activerecord" target="_blank"&gt;ActiveRecord&lt;/a&gt;.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;I really like ActiveRecord and I would recommend using it on .NET projects when there is the need an OR Mapping tool.&amp;nbsp; The fault lay was us, the developers.&amp;nbsp; We didn't pay enough attention to the fact that there was a database at the end of the calls that the repository was making.&amp;nbsp; We didn't spot that some of the calls which our test code was making were potentially very expensive in real usage scenarios.&amp;nbsp; And so we got bitten by the law of leaky abstractions, which manifest itself through a number of bad usage patterns which caused immediate performance problems.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Read the &lt;a href="http://no-new-ideas.blogspot.com/2008/11/activerecord-lessons-learnt-1-never.html" target="_blank"&gt;full post&lt;/a&gt; for other lessons.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:efa37fb7-85d3-4fa4-8953-c4793984245c" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/ActiveRecord" rel="tag"&gt;ActiveRecord&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6723571" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/444438450" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psteele/archive/tags/ActiveRecord/default.aspx">ActiveRecord</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/11/06/activerecord-never-forget-there-s-a-database.aspx</feedburner:origLink></item><item><title>Generate ActiveRecord Classes from Existing DB Schema</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/438082475/generate-activerecord-classes-from-existing-db-schema.aspx</link><pubDate>Fri, 31 Oct 2008 14:02:13 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6714132</guid><dc:creator>PSteele</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/10/31/generate-activerecord-classes-from-existing-db-schema.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=generatorstudio" target="_blank"&gt;GeneratorStudio&lt;/a&gt; is a project on &lt;a href="http://www.codeplex.com/" target="_blank"&gt;CodePlex&lt;/a&gt; used to automate the creation of &lt;a href="http://www.castleproject.org/activerecord" target="_blank"&gt;Castle ActiveRecord&lt;/a&gt; classes from existing database schema.&amp;nbsp; I haven't downloaded it yet to play around with it, but it looks like it would be a nice thing to have if you have a large (or even medium) schema that's already in production and you'd like to start using Castle ActiveRecord for DB access.&lt;/p&gt; &lt;p&gt;More info &lt;a href="http://blog.fryhard.com/archive/2008/10/31/generator_studio_available_on_codeplex.aspx" target="_blank"&gt;here&lt;/a&gt; and &lt;a href="http://www.darkside.co.za/archive/2008/10/30/generator-studio-released-on-codeplex.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0c8bdd4a-8a4b-45ef-a959-ff5ba09404b1" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/ActiveRecord" rel="tag"&gt;ActiveRecord&lt;/a&gt;, &lt;a href="http://technorati.com/tags/ORM" rel="tag"&gt;ORM&lt;/a&gt;, &lt;a href="http://technorati.com/tags/CodePlex" rel="tag"&gt;CodePlex&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6714132" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/438082475" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psteele/archive/tags/ActiveRecord/default.aspx">ActiveRecord</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/10/31/generate-activerecord-classes-from-existing-db-schema.aspx</feedburner:origLink></item><item><title>Mock Databases and ActiveRecord</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/437601197/mock-databases-and-activerecord.aspx</link><pubDate>Fri, 31 Oct 2008 02:51:30 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6713405</guid><dc:creator>PSteele</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/10/30/mock-databases-and-activerecord.aspx#comments</comments><description>&lt;p&gt;Fellow SRT employee &lt;a href="http://www.cptloadtest.com/default.aspx"&gt;Jay Harris&lt;/a&gt; has a great post on using SQLite's in-memory database feature to &lt;a href="http://www.cptloadtest.com/2008/10/31/UnitTestingActiveRecordApplicationsUsingMockDatabases.aspx"&gt;mock his database&lt;/a&gt;.&amp;#160; He points out a few of the factors that drove him to investigate such an approach:&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;I did not want a SQL Server installation to be a requirement for me, the other developers, and my Continuous Integration server. &lt;/li&gt;      &lt;li&gt;I wanted something fast. I didn't want to have to wait for SQL Server to build / tear down my schema. &lt;/li&gt;      &lt;li&gt;I wanted something isolated, so the other developers, and my CI server, and I wouldn't have contention over the same database, but didn't want to have to deal with independent SQL Server instances for everyone.&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://www.cptloadtest.com/2008/10/31/UnitTestingActiveRecordApplicationsUsingMockDatabases.aspx"&gt;Check it out&lt;/a&gt;.&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:61dcb729-56f4-4d74-87d5-e3ce7d120679" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/ActiveRecord" rel="tag"&gt;ActiveRecord&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SQLite" rel="tag"&gt;SQLite&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Mock" rel="tag"&gt;Mock&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6713405" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/437601197" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psteele/archive/tags/ActiveRecord/default.aspx">ActiveRecord</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/10/30/mock-databases-and-activerecord.aspx</feedburner:origLink></item><item><title>SRT to host PDC Keynote Remote Viewing</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/426584678/srt-to-host-pdc-keynote-remote-viewing.aspx</link><pubDate>Mon, 20 Oct 2008 16:25:15 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6692921</guid><dc:creator>PSteele</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/10/20/srt-to-host-pdc-keynote-remote-viewing.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.eventbrite.com/org/104580978?s=1021838"&gt;Register now&lt;/a&gt;.&amp;nbsp; Seating is limited.&amp;nbsp; Thanks to Microsoft for sponsoring lunch!&amp;nbsp; Here's the details:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;SRT Solutions will be hosting a remote viewing of the Ray Ozzie Keynotes, live from the PDC conference. Join SRT staff and other .NET developers from the community to watch the keynote live and to discuss it afterward. &lt;p&gt;Microsoft is sponsoring lunch. &lt;p&gt;Pre-registration is required.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Please note that there are two keynote events, one on Monday and one on Tuesday.&amp;nbsp; You must register for each one you plan on attending.&amp;nbsp; And &lt;a href="http://weblogs.asp.net/psteele/archive/2007/09/17/srt-s-new-offices.aspx"&gt;since seating is limited&lt;/a&gt;, please only register if you know you can make it.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f3781a6b-29ec-40c5-abf8-7931aec01c28" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/PDC" rel="tag"&gt;PDC&lt;/a&gt;, &lt;a href="http://technorati.com/tags/SRT%20Solutions" rel="tag"&gt;SRT Solutions&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6692921" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/426584678" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/10/20/srt-to-host-pdc-keynote-remote-viewing.aspx</feedburner:origLink></item><item><title>Tweaking my color settings</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/416344276/tweaking-my-color-settings.aspx</link><pubDate>Fri, 10 Oct 2008 01:40:47 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6667975</guid><dc:creator>PSteele</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/10/09/tweaking-my-color-settings.aspx#comments</comments><description>&lt;p&gt;Like many developers, I spend a lot of time reading and writing code every day.&amp;nbsp; After hearing so many developers praise the "dark background/light text" colors that have become popular, I decided to switch too.&amp;nbsp; I did some research and &lt;a href="http://blog.wekeroad.com/2007/10/17/textmate-theme-for-visual-studio-take-2/"&gt;found a theme I really liked&lt;/a&gt;.&amp;nbsp; I tweaked it very slightly and have been using it ever since.&amp;nbsp; It is &lt;strong&gt;much&lt;/strong&gt; easier on the eyes.&lt;/p&gt; &lt;p&gt;However, one thing has been bothering me.&amp;nbsp; When Visual Studio stops in an exception or when an exception is thrown and Visual Studio highlights the catch block, the coloring is almost unreadable.&amp;nbsp; Here's a quick sample:&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="470" alt="image" src="http://www.lotsofemail.com/blog_images/Tweakingmycolorsettings_130D8/image.png" width="709" border="0"&gt; &lt;/p&gt; &lt;p&gt;I remember doing a quick run through trying to find what this type of code block was called so I could change the color, but had no luck.&lt;/p&gt; &lt;p&gt;Today, I couldn't stand it anymore.&amp;nbsp; I methodically searched through every color option and finally found the one that corresponds to this case:&lt;/p&gt; &lt;h2&gt;Read-Only Region&lt;/h2&gt; &lt;p&gt;Looking in the Options dialog, the "Sample" shown looks okay:&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="382" alt="image" src="http://www.lotsofemail.com/blog_images/Tweakingmycolorsettings_130D8/image_3.png" width="644" border="0"&gt; &lt;/p&gt; &lt;p&gt;But that's because the "Item Foreground" is set to "Default" and VS assumes black.&amp;nbsp; Since my default text color is White, this combination is horrible.&amp;nbsp; I picked a new color from the background color dropdown (Olvie) and now my eyes are much happier:&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="470" alt="image" src="http://www.lotsofemail.com/blog_images/Tweakingmycolorsettings_130D8/image_4.png" width="709" border="0"&gt; &lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:1d73d4f6-2709-4f8d-9df2-a05252d8642b" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/Visual%20Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Color%20Scheme" rel="tag"&gt;Color Scheme&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6667975" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/416344276" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/10/09/tweaking-my-color-settings.aspx</feedburner:origLink></item><item><title>ActiveRecord and a Custom NHibernate PrimitiveType</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/414374200/activerecord-and-a-custom-nhibernate-primitivetype.aspx</link><pubDate>Wed, 08 Oct 2008 01:54:29 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6664549</guid><dc:creator>PSteele</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/10/07/activerecord-and-a-custom-nhibernate-primitivetype.aspx#comments</comments><description>&lt;p&gt;I was intrigued by &lt;a href="http://stevesmithblog.com/"&gt;Steve Smith&lt;/a&gt;'s blog post yesterday about &lt;a href="http://stevesmithblog.com/blog/reducing-sql-lookup-tables-and-function-properties-in-nhibernate/"&gt;reducing SQL Lookup tables in nHibernate&lt;/a&gt;.&amp;nbsp; He gave an example of a WorkOrderStatus class the exposed the actual status as a &lt;a href="http://en.wikipedia.org/wiki/POCO"&gt;POCO&lt;/a&gt; object that wasn't stored in the database.&amp;nbsp; What really piqued my interest was the following comment:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;NHibernate can map this status directly if you create a WorkOrderStatusType class that inherits from NHibernate.Type.PrimitiveType and overrides its methods.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;I never knew nHibernate supported this type of feature (never needed it or thought about it).&amp;nbsp; As I'm an avid &lt;a href="http://www.castleproject.org/activerecord"&gt;ActiveRecord&lt;/a&gt; user, I decided to see how I would implement a custom nHibernate PrimitiveType and utilize it via ActiveRecord.&amp;nbsp; Turns out it was pretty easy!&amp;nbsp; The full source is available from &lt;a href="http://code.google.com/p/patricksteele/"&gt;my GoogleCode page&lt;/a&gt; either through SVN or simply a ZIP download.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;A quick note before we begin: &lt;/strong&gt;I didn't find a whole lot of documentation on extending PrimitiveType and implementing your own.&amp;nbsp; I reviewed some nHibernate code and I think I got the general implementation right, but can't be sure it'll work 100% of the time.&amp;nbsp; It was a proof-of-concept project.&lt;/p&gt; &lt;h3&gt;ActiveRecord Setup&lt;/h3&gt; &lt;p&gt;I decided I'd use SQLite for this sample since it's perfect for this type of job -- small, compact and no install required.&amp;nbsp; I can poke around the database to check schema and data using the &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/5817"&gt;SQLite addon for Firefox&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Instead of stealing Steve's WorkOrderStatus, I decided to go with a schema that has a simple Company object, and that Company object has a CompanyType defined.&amp;nbsp; Instead of defining a lookup table just for company types, I'll create a CompanyType class that derives from NHibernate.Type.PrimitiveType and let nHibernate do the loading/saving.&lt;/p&gt; &lt;p&gt;First, the CompanyType.&amp;nbsp; For this demo, it's a simple object with a Description (string) and a Value (integer).&amp;nbsp; The Value is what is actually saved to the database (note: this isn't the entire class -- just the basics):&lt;/p&gt; &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 381px; background-color: #f4f4f4; max-height: 200px"&gt; &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CompanyType : NHibernate.Type.PrimitiveType&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; CompanyType Software = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CompanyType() { Description = &lt;span style="color: #006080"&gt;"Software"&lt;/span&gt;, Value = 1 };&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; CompanyType Manufacturing = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CompanyType() { Description = &lt;span style="color: #006080"&gt;"Manufacturing"&lt;/span&gt;, Value = 2 };&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; CompanyType Insurance = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CompanyType() { Description = &lt;span style="color: #006080"&gt;"Insurance"&lt;/span&gt;, Value = 3 };&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;readonly&lt;/span&gt; CompanyType[] AllTypes = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CompanyType[] { Software, Manufacturing, Insurance };&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Description { get; set; }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Value { get; set; }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; ToString()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Description;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CompanyType()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        : &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;(SqlTypeFactory.Int32)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;I've defined an AllTypes[] that I'll use to find the matching CompanyType when nHibernate reads the integer from the database.&amp;nbsp; The ctor calls the base class ctor and tells nHibernate what data type this new PrimitiveType is based on (the schema in the database will be an integer).&amp;nbsp; I also overrode ToString() to return the Description property to make debugging easier.&lt;/p&gt;
&lt;p&gt;The Company record is pretty simple too.&amp;nbsp; When we get to the CompanyType, we tell ActiveRecord (which works through nHibernate) the column type for the column (our custom PrimitiveType):&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;[ActiveRecord]&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Company : ActiveRecordBase&amp;lt;Company&amp;gt;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    [PrimaryKey(Generator = PrimaryKeyType.Identity)]&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Id { get; set; }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    [Property]&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    [Property]&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DateTime InceptionDate { get; set; }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    [Property(ColumnType = &lt;span style="color: #006080"&gt;"ARPrimitiveType.Model.CompanyType, ARPrimitiveType"&lt;/span&gt;)]&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CompanyType CompanyType { get; set; }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; ToString()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Name;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Implementing the required methods in CompanyType was pretty easy.&amp;nbsp; I'm not sure when DefaultValue is used, so I just return a CompanyType of Software:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; DefaultValue&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; CompanyType.Software; }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;ObjectToSQLString seems to want to convert your PrimitiveType (CompanyType) to a string value that can be used by the database.&amp;nbsp; So we'll convert our Value property to a string:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; ObjectToSQLString(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;, NHibernate.Dialect.Dialect dialect)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    CompanyType type = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt; &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; CompanyType;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; type.Value.ToString();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The PrimitiveType class indicated the actual type of data stored in the database (a 32-bit integer for our CompanyType):&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; Type PrimitiveClass&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Int32); }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The FromStringValue and two Get overloads both need to do the same thing: Take a representation of the database value and convert it to our PrimitiveType (a CompanyType).&amp;nbsp; For this I created a single method that converts the database integer back to a CompanyType instance using a LINQ query on the AllTypes array:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; FromStringValue(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; xml)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetCompanyType(xml);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; Get(System.Data.IDataReader rs, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; name)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetCompanyType(rs[name]);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; Get(System.Data.IDataReader rs, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; index)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetCompanyType(rs[index]);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; GetCompanyType(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; val)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (val == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    {&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; DefaultValue;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; v = Int32.Parse(val.ToString());&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; AllTypes.First(x =&amp;gt; x.Value == v);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Next, nHibernate needs to know how to stick a CompanyType into the database.&amp;nbsp; In the Set method, we take our "Value" property and place it in the IDbCommand.Parameters collection:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Set(System.Data.IDbCommand cmd, &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; index)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    CompanyType type = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt; &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; CompanyType;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    DbParameter param = cmd.Parameters[index] &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; DbParameter;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    param.Value = type.Value;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Finally, nHibernate wants to know that type of data this PrimitiveType is exposing to the outside world (our application):&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; Type ReturnedClass&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(CompanyType); }&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;We've now implemented a PrimitiveType that will allow our application to program against a CompanyType object while the database deals with an integer.&lt;/p&gt;
&lt;h3&gt;Sample Code&lt;/h3&gt;
&lt;p&gt;Now we can create Company objects like this:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;Company c = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Company();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;c.Name = &lt;span style="color: #006080"&gt;"ABC Software"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;c.InceptionDate = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DateTime(2008, 1, 1);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;c.CompanyType = CompanyType.Insurance;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;c.Save();&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If you look in the database, the Company table has a field called "CompanyType".&amp;nbsp; It's an integer and the record above will populate the CompanyType with a value of 3.&lt;/p&gt;
&lt;p&gt;You can use this object in HQL queries too:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; HQLTest()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    SimpleQuery&amp;lt;Company&amp;gt; query = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SimpleQuery&amp;lt;Company&amp;gt;(&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        &lt;span style="color: #006080"&gt;"from Company c where c.CompanyType = ?"&lt;/span&gt;, CompanyType.Manufacturing);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    Company[] results = query.Execute();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Or, if you prefer, you can use nHibernate's DetachedCriteria:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CriteriaTest()&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    DetachedCriteria query = DetachedCriteria.For&amp;lt;Company&amp;gt;(&lt;span style="color: #006080"&gt;"Company"&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        .Add(Expression.Eq(&lt;span style="color: #006080"&gt;"CompanyType"&lt;/span&gt;, CompanyType.Manufacturing));&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    Company[] results = Company.FindAll(query);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;This was a fun demo project to create.&amp;nbsp; It's always nice to learn something new about a tool you use often (ActiveRecord/nHibernate).&amp;nbsp; This was a good proof-of-concept, but needs a lot more testing and error handling before it could be used in production.&amp;nbsp; You're free to use the code as-is, but there are no guarantees as to its correctness.&lt;/p&gt;
&lt;p&gt;If anyone is aware of any errors I've made in implementing a custom PrimitiveType, please feel free to &lt;a href="http://weblogs.asp.net/psteele/contact.aspx"&gt;let me know&lt;/a&gt;.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f97e3c7e-1b9b-47c3-891c-f3613d4d2db4" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/ActiveRecord" rel="tag"&gt;ActiveRecord&lt;/a&gt;, &lt;a href="http://technorati.com/tags/nHibernate" rel="tag"&gt;nHibernate&lt;/a&gt;, &lt;a href="http://technorati.com/tags/PrimitiveType" rel="tag"&gt;PrimitiveType&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6664549" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/414374200" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psteele/archive/tags/ActiveRecord/default.aspx">ActiveRecord</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/10/07/activerecord-and-a-custom-nhibernate-primitivetype.aspx</feedburner:origLink></item><item><title>Project Eurler #12</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/411209203/project-eurler-12.aspx</link><pubDate>Sat, 04 Oct 2008 15:43:28 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6657642</guid><dc:creator>PSteele</dc:creator><slash:comments>1</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/10/04/project-eurler-12.aspx#comments</comments><description>&lt;p&gt;I see that &lt;a href="http://srtsolutions.com/blogs/billwagner/archive/2008/10/02/euler-problem-11-or-it-s-about-time-i-wrote-some-code.aspx"&gt;Bill did Euler #11&lt;/a&gt; earlier this week so I thought I'd &lt;a href="http://projecteuler.net/index.php?section=problems&amp;amp;id=12"&gt;tackle #12&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;The first thing I wanted to do was write a routine to generate a triangle number.&amp;nbsp; As we've seen &lt;a href="http://weblogs.asp.net/psteele/archive/tags/Project+Euler/default.aspx"&gt;throughout this series&lt;/a&gt;, LINQ can come in very handy:&lt;/p&gt; &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt; &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; TriangleOf(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; number)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Enumerable.Range(1, number).Sum();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Now I needed to find all the divisors of a number.&amp;nbsp; I have to "&lt;a href="http://en.wikipedia.org/wiki/Eating_crow"&gt;eat crow&lt;/a&gt;" and admit the first time I did this, I used the brute force method:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; IEnumerable&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; FindAllDivisors(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; number)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; from d &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; Enumerable.Range(1, number)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;           &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; number % d == 0&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;           select d;&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;I didn't like it.&amp;nbsp; I knew I could use the square root to reduce the number of iterations in this loop, but that would mean every "select" of my LINQ query would need to return more than one result -- the divisor and the number / divisor.&amp;nbsp; I couldn't see any easy way to create two results from a query so I just left this as-is and moved on to actually solving the problem.&lt;/p&gt;
&lt;p&gt;Again, LINQ made this extremely easy:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;var answer = (from d &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; Enumerable.Range(1, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;.MaxValue)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;          &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; FindAllDivisors(TriangleOf(d)).Count() &amp;gt; 500&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;          select d).Take(1);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;As you might expect, this wasn't very quick.&amp;nbsp; In fact, I let it run overnight since I didn't start on this till later in the evening.&amp;nbsp; It ended up taking 5 hours and 15 minutes.&amp;nbsp; NOT A SOLUTION!&lt;/p&gt;
&lt;p&gt;So I started researching how I could return multiple items from a single LINQ query.&amp;nbsp; The answer was embarassingly simple -- create an array!&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;var values = from d &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; Enumerable.Range(1, (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)Math.Sqrt(number))&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;         &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; number % d == 0&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;         select &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { d, number / d };&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;But now I've got an IEnumeable&amp;lt;int[]&amp;gt; and I want all the divisors together in an IEnumerable&amp;lt;int&amp;gt;.&amp;nbsp; I looked around at the extension methods on IEnumerable&amp;lt;T&amp;gt; and found &lt;a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.selectmany.aspx"&gt;SelectMany&lt;/a&gt;.&amp;nbsp; This method will project each element into an IEnumerable&amp;lt;T&amp;gt; and flatten the result into a single sequence.&lt;/p&gt;
&lt;p&gt;So my revised FindAllDivisors now looks like this:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; IEnumerable&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; FindAllDivisors(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; number)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    var values = from d &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; Enumerable.Range(1, (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)Math.Sqrt(number))&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;             &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; number % d == 0&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;             select &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] { d, number / d };&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; values.SelectMany(x =&amp;gt; x);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Now this completes in a respectable 5 - 6 seconds.&amp;nbsp; MUCH better than my first attempt.&amp;nbsp; Sometimes, &lt;a href="http://en.wikipedia.org/wiki/Kiss_principle"&gt;KISS&lt;/a&gt; only gets you so far.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e1342225-a35d-4ef8-8621-3150d825ace5" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/Euler" rel="tag"&gt;Euler&lt;/a&gt;, &lt;a href="http://technorati.com/tags/IEnumerable" rel="tag"&gt;IEnumerable&lt;/a&gt;, &lt;a href="http://technorati.com/tags/SelectMany" rel="tag"&gt;SelectMany&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6657642" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/411209203" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psteele/archive/tags/Project+Euler/default.aspx">Project Euler</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/10/04/project-eurler-12.aspx</feedburner:origLink></item><item><title>Playing around with ASP.NET MVC</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/409744315/playing-around-with-asp-net-mvc.aspx</link><pubDate>Thu, 02 Oct 2008 23:48:50 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6654848</guid><dc:creator>PSteele</dc:creator><slash:comments>5</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/10/02/playing-around-with-asp-net-mvc.aspx#comments</comments><description>&lt;p&gt;As I'm a big fan of Castle Project's &lt;a href="http://www.castleproject.org/monorail"&gt;MonoRail&lt;/a&gt;, I often get asked my opinion of the &lt;a href="http://www.codeplex.com/aspnet/Wiki/View.aspx?title=MVC"&gt;ASP.NET MVC&lt;/a&gt; stuff Microsoft is working on.&amp;nbsp; And I always have the same answer -- I've seen some demos but haven't actually played around with it.&amp;nbsp; So I took some time tonight and installed it.&lt;/p&gt; &lt;h3&gt;Installation&lt;/h3&gt; &lt;p&gt;You can download the ASP.NET MVC Preview 5 release &lt;a href="http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16775"&gt;here&lt;/a&gt;.&amp;nbsp; Double-click on the MSI and you get the usual welcome screen.&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="396" alt="Step1" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/Step1.png" width="503" border="0"&gt; &lt;/p&gt; &lt;p&gt;As always, there's a EULA to accept.&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="396" alt="Step2" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/Step2.png" width="503" border="0"&gt; &lt;/p&gt; &lt;p&gt;After that, you're ready to install.&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="396" alt="Step3" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/Step3.png" width="503" border="0"&gt; &lt;/p&gt; &lt;p&gt;And then you're done!&amp;nbsp; Painless and easy.&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="396" alt="Step4" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/Step4.png" width="503" border="0"&gt; &lt;/p&gt; &lt;h3&gt;My First Project&lt;/h3&gt; &lt;p&gt;After installation completed, I started up Visual Studio 2008.&amp;nbsp; At this point, the &lt;a href="http://www.roland-weigelt.de/ghostdoc/"&gt;GhostDoc&lt;/a&gt; configuration screen appeared.&amp;nbsp; I had to repeat my GhostDoc set up.&amp;nbsp; That was weird!&amp;nbsp; Don't know if that had anything to do with the ASP.NET MVC install, but I hadn't done anything else with my VS2008 installation recently.&lt;/p&gt; &lt;p&gt;You'll now have a new Web project type called "ASP.NET MVC Web Application".&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="475" alt="NewProject" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/NewProject.png" width="687" border="0"&gt; &lt;/p&gt; &lt;p&gt;After selecting this I was asked if I wanted to add a unit test project as well.&amp;nbsp; Very nice!&amp;nbsp; Obviously, I selected "Yes".&amp;nbsp; :)&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="328" alt="UnitTestsToo" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/UnitTestsToo.png" width="475" border="0"&gt; &lt;/p&gt; &lt;p&gt;My solution was now all set up and ready to go:&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="414" alt="NewSolutionReady" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/NewSolutionReady.png" width="320" border="0"&gt; &lt;/p&gt; &lt;p&gt;Notice the project is pre-populated with folders for my controllers, models and views.&amp;nbsp; The web.config is also fully configured.&amp;nbsp; At this point, I clicked "Run" to see what would happen.&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="220" alt="EnableDebugging" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/EnableDebugging.png" width="484" border="0"&gt; &lt;/p&gt; &lt;p&gt;By default, the web.config is not set up for debugging.&amp;nbsp; I took the default and let VS.NET set up my config for debugging.&lt;/p&gt; &lt;p&gt;And now my first ASP.NET MVC project was up and running!&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/NewSolutionRunning.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="194" alt="NewSolutionRunning" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/NewSolutionRunning_thumb.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;h3&gt;Comparison to MonoRail&lt;/h3&gt; &lt;p&gt;Now I started poking around the directory structure.&amp;nbsp; I noticed that instead of a "layouts" folder they place their master pages ("layouts" in MonoRail) inside a "shared" folder.&amp;nbsp; Sounds similar to MonoRail's shared views.&lt;/p&gt; &lt;p&gt;I noticed that the view pages are still ASPX pages and contain a code-behind file.&amp;nbsp; This seems kind of odd to me as I'm accustomed to MonoRail's view files (mostly NVelocity) -- a single file that contains everything needed to render the view; no more, no less.&amp;nbsp; I could see that without discipline, the code-behind files could be bloated with business logic when it should only contain view logic.&amp;nbsp; Be careful!&lt;/p&gt; &lt;p&gt;Poking around the pre-built pages I noticed most of the "ViewData" (PropertyBag for you MonoRail people) output was wrapped in Html.Encode.&amp;nbsp; It would seem to me that you'd want to, by default, &lt;strong&gt;&lt;em&gt;always&lt;/em&gt;&lt;/strong&gt; HTML encode your output (like MonoRail does).&amp;nbsp; I think raw output of view data is the exception rather than the rule.&amp;nbsp; &lt;a href="http://blog.codeville.net/2007/12/19/aspnet-mvc-prevent-xss-with-automatic-html-encoding/"&gt;Others&lt;/a&gt; think it should be this way too.&amp;nbsp; Again, be careful!&lt;/p&gt; &lt;h3&gt;Adding a New View&lt;/h3&gt; &lt;p&gt;So it's time to start adding a little bit of my own code to this sample app.&amp;nbsp; I started with adding a new view.&amp;nbsp; When you do this, make sure you add a new "MVC View Page" and not the usual "Web Form":&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="425" alt="PickProperPage" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/PickProperPage.png" width="687" border="0"&gt; &lt;/p&gt; &lt;p&gt;The page popped up and I noticed something right away: There's no way to pick your master page when creating a new MVC View Page.&amp;nbsp; I'm sure this is just one of those things that don't exist yet.&amp;nbsp; I know that this selection step is available for web forms so it's probably just a matter of time before the ASP.NET MVC stuff supports this.&lt;/p&gt; &lt;p&gt;But, since it doesn't, you'll need to add the MasterPageFile attribute yourself as well as any ContentPlaceholder tags.&amp;nbsp; I grabbed them from one of the sample pages.&lt;/p&gt; &lt;p&gt;So now I just dumped some code real quick into the view.&amp;nbsp; As I typed, I noticed the Visual Studio was complaining about what I was typing:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/WhereIsViewDataDefined.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="185" alt="WhereIsViewDataDefined" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/WhereIsViewDataDefined_thumb.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;It didn't like my "Html.Encode" nor my "ViewData" references.&amp;nbsp; I copied these right from another page?!&amp;nbsp; What was I missing?&amp;nbsp; An import perhaps?&amp;nbsp; Nope, the imports on the sample pages are the same as mine.&amp;nbsp; Then it hit me -- these view pages (like web forms pages) inherit from a base class.&amp;nbsp; That base class probably exposes the Html and ViewData objects.&amp;nbsp; Since I just created this page (and haven't compiled), the intellisense wasn't picking up the proper settings.&amp;nbsp; So even though I had the red squiggle's, I hit the build button.&amp;nbsp; Everything built fine and my page errors went away.&lt;/p&gt; &lt;p&gt;I put a line of code in one of the controllers to stick my name in the ViewData.&amp;nbsp; Then I added my new page (action) to the menu:&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/AddLinkToMyAction.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="185" alt="AddLinkToMyAction" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/AddLinkToMyAction_thumb.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;I ran the project and clicked on my link:&lt;/p&gt; &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="617" alt="SeeCheckThis" src="http://www.lotsofemail.com/blog_images/PlayingaroundwithASP.NETMVC_11658/SeeCheckThis.png" width="845" border="0"&gt; &lt;/p&gt; &lt;p&gt;Ok -- I admit it.&amp;nbsp; Not too exciting!&amp;nbsp; And it barely scratches the surface of what you can do with ASP.NET MVC.&amp;nbsp; But I think I've showed it's pretty easy to install it and start using it right away -- even if you're not familiar with the MVC pattern.&lt;/p&gt; &lt;p&gt;I'll continue to use MonoRail for my web projects as it's more mature than the ASP.NET MVC stuff.&amp;nbsp; But I'll definitely be coming back to this stuff from time to time and playing around with it.&amp;nbsp; I think Microsoft has made the right decision in creating a whole new architecture for implementation of the MVC pattern and not trying to jam it into the Web Forms engine.&amp;nbsp; That would have been a huge mistake!&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ca898e9b-12dd-4506-bfc0-f2d5589b4a31" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/MonoRail" rel="tag"&gt;MonoRail&lt;/a&gt;, &lt;a href="http://technorati.com/tags/ASP.NET%20MVC" rel="tag"&gt;ASP.NET MVC&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6654848" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/409744315" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psteele/archive/tags/MonoRail/default.aspx">MonoRail</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/10/02/playing-around-with-asp-net-mvc.aspx</feedburner:origLink></item><item><title>ActiveRecord + HQL and an "IN" clause</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/408846916/activerecord-hql-and-an-quot-in-quot-clause.aspx</link><pubDate>Thu, 02 Oct 2008 02:26:57 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6651337</guid><dc:creator>PSteele</dc:creator><slash:comments>9</slash:comments><comments>http://weblogs.asp.net/psteele/archive/2008/10/01/activerecord-hql-and-an-quot-in-quot-clause.aspx#comments</comments><description>&lt;p&gt;Late last year as I was using &lt;a href="http://www.castleproject.org/monorail"&gt;MonoRail&lt;/a&gt; and &lt;a href="http://www.castleproject.org/activerecord"&gt;ActiveRecord&lt;/a&gt; for a simple web application.&amp;nbsp; I was helping my local church find volunteers with various skills to teach some basic computer courses to the the church staff.&amp;nbsp; I wanted to keep track of the volunteers along with the skills they had.&amp;nbsp; I used this as another opportunity to learn more about MonoRail and ActiveRecord.&lt;/p&gt; &lt;h3&gt;The Database&lt;/h3&gt; &lt;p&gt;The database couldn't be any simpler: I had a Trainer table, a Skill table and a join table to keep track of the 1:M relationship between a Trainer and their skills.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.lotsofemail.com/blog_images/ActiveRecordHQLandanINclause_139D6/image.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="391" alt="image" src="http://www.lotsofemail.com/blog_images/ActiveRecordHQLandanINclause_139D6/image_thumb.png" width="511" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;h3&gt;ActiveRecord&lt;/h3&gt; &lt;p&gt;The ActiveRecord classes were equally easy to define (in fact, I created the ActiveRecord objects first and then used &lt;a href="http://www.castleproject.org/activerecord/documentation/trunk/usersguide/schemagen.html"&gt;schema generation&lt;/a&gt; to generate the actual database tables).&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.lotsofemail.com/blog_images/ActiveRecordHQLandanINclause_139D6/image_3.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="454" alt="image" src="http://www.lotsofemail.com/blog_images/ActiveRecordHQLandanINclause_139D6/image_thumb_3.png" width="392" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;h3&gt;The Problem Query&lt;/h3&gt; &lt;p&gt;I used MonoRail to put together a couple of web pages for editing of the data.&amp;nbsp; Then I created a "Report" page that allowed me to pick an arbritrary set of skills and get a list of all Trainers that had that particular skill.&lt;/p&gt; &lt;p&gt;In SQL, I'd use an "IN" clause like this:&lt;/p&gt; &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt; &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;select&lt;/span&gt; t.*&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;from&lt;/span&gt; Trainer t&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;inner&lt;/span&gt; &lt;span style="color: #0000ff"&gt;join&lt;/span&gt; TrainerSkills ts &lt;span style="color: #0000ff"&gt;on&lt;/span&gt; ts.TrainerId = t.id &lt;span style="color: #0000ff"&gt;and&lt;/span&gt; ts.SkillId &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; (2,6)&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In the query above, the IN clause of (2,6) contains the primary keys of the two Skill records selected by the user.&amp;nbsp; Pretty simple SQL.&amp;nbsp; I needed to figure out how to get this in &lt;a href="http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html"&gt;HQL&lt;/a&gt; (Hibernate Query Language).&lt;/p&gt;
&lt;p&gt;My first attempt was an almost exact port of the SQL syntax (HQL is very similar to SQL anyway):&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Trainer[] FindBySkillset(Skill[] skills)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    SimpleQuery&amp;lt;Trainer&amp;gt; q = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SimpleQuery&amp;lt;Trainer&amp;gt;(&lt;span style="color: #006080"&gt;"from Trainer t where t.Skills in (?)"&lt;/span&gt;, skills);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; q.Execute();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;That didn't work.&amp;nbsp; I got some cryptic error about having an "unindexed collection before []".&amp;nbsp; So then I tried a variation of the above query where I used a named parameter and specifically indicated the parameter was a list:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Trainer[] FindBySkillset(Skill[] skills)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    SimpleQuery&amp;lt;Trainer&amp;gt; q = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SimpleQuery&amp;lt;Trainer&amp;gt;(&lt;span style="color: #006080"&gt;"from Trainer t where t.Skills in (:skills)"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    q.SetParameterList(&lt;span style="color: #006080"&gt;"skills"&lt;/span&gt;, skills);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; q.Execute();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;That gave me another odd error.&amp;nbsp; After digging around in the HQL docs as well as finding a forum post somewhere that showed a slightly different IN clause, I found out that I needed to "flip" the way I use the IN clause.&amp;nbsp; In SQL, you'd say "WHERE xxx IN (values...)".&amp;nbsp; In HQL, you give the list of values first and use the "elements" keyword to indicate which collection to match up those values to.&amp;nbsp; The final working query:&lt;/p&gt;
&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; max-height: 200px"&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Trainer[] FindBySkillset(Skill[] skills)&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;{&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    SimpleQuery&amp;lt;Trainer&amp;gt; q = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SimpleQuery&amp;lt;Trainer&amp;gt;(&lt;span style="color: #006080"&gt;"from Trainer t where ? in elements (t.Skills)"&lt;/span&gt;, skills);&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; q.Execute();&lt;/pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Hopefully this helps out someone else.&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8ce05be9-806e-4a65-9258-41f2ed110425" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati tags: &lt;a href="http://technorati.com/tags/MonoRail" rel="tag"&gt;MonoRail&lt;/a&gt;, &lt;a href="http://technorati.com/tags/ActiveRecord" rel="tag"&gt;ActiveRecord&lt;/a&gt;, &lt;a href="http://technorati.com/tags/HQL" rel="tag"&gt;HQL&lt;/a&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6651337" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetmvp/~4/408846916" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/psteele/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psteele/archive/tags/MonoRail/default.aspx">MonoRail</category><category domain="http://weblogs.asp.net/psteele/archive/tags/ActiveRecord/default.aspx">ActiveRecord</category><feedburner:origLink>http://weblogs.asp.net/psteele/archive/2008/10/01/activerecord-hql-and-an-quot-in-quot-clause.aspx</feedburner:origLink></item><item><title>The Days of Platter-based Hard Drives are numbered</title><link>http://feeds.feedburner.com/~r/dotnetmvp/~3/407256609/the-days-of-platter-based-hard-drives-are-numbered.aspx</link><pubDate>Tue, 30 Sep 2008 12:42:56 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6648543</guid><dc:creator>PSteele</