<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Introduction</title>
        <link>http://blogs.hibernatingrhinos.com/nhibernate/category/2.aspx</link>
        <description>Introduction to the usage of NHibernate</description>
        <language>en-US</language>
        <copyright>NHibernate's Answers</copyright>
        <managingEditor>gnschenker@gmail.com</managingEditor>
        <generator>Subtext Version 2.0.0.43</generator>
        <item>
            <title>Article series on NHibernate and Fluent NHibernate &amp;ndash; Part 3</title>
            <link>http://blogs.hibernatingrhinos.com/nhibernate/archive/2009/09/01/article-series-on-nhibernate-and-fluent-nhibernate-ndash-part-3.aspx</link>
            <description>&lt;p&gt;Today the third part of my series on NHibernate and Fluent NHibernate went live. It took a little bit longer due to work overload. You can read it &lt;a href="http://dotnetslackers.com/articles/ado_net/Your-very-first-NHibernate-application-Part-3.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;Summary&lt;/h2&gt;  &lt;p&gt;In part 3 of this article series about NHibernate and Fluent NHibernate I have discussed how to let Fluent NHibernate automatically map a domain model to a data model. We have realized that FNH provides a reasonable mapping out of the box by using default conventions. I have shown how one can implement user defined conventions which will influence how the mapping is defined on a very fine grained level. I have also shown that if we use a base class in our domain which implements common functionality we can instruct FNH to ignore this class and just map the “real” entities.&lt;/p&gt;  &lt;p&gt;FNH with its auto mapping feature reduces the task of mapping a complex domain to an underlying data model to just a few keystrokes. And as is always true: less code results in less bugs and less maintenance overhead.&lt;/p&gt;&lt;img src="http://blogs.hibernatingrhinos.com/nhibernate/aggbug/53.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>NHibernate's Answers</dc:creator>
            <guid>http://blogs.hibernatingrhinos.com/nhibernate/archive/2009/09/01/article-series-on-nhibernate-and-fluent-nhibernate-ndash-part-3.aspx</guid>
            <pubDate>Wed, 02 Sep 2009 04:51:14 GMT</pubDate>
            <wfw:comment>http://blogs.hibernatingrhinos.com/nhibernate/comments/53.aspx</wfw:comment>
            <comments>http://blogs.hibernatingrhinos.com/nhibernate/archive/2009/09/01/article-series-on-nhibernate-and-fluent-nhibernate-ndash-part-3.aspx#feedback</comments>
            <slash:comments>136</slash:comments>
            <wfw:commentRss>http://blogs.hibernatingrhinos.com/nhibernate/comments/commentRss/53.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Article series on NHibernate and Fluent NHibernate &amp;ndash; Part 2</title>
            <link>http://blogs.hibernatingrhinos.com/nhibernate/archive/2009/04/16/article-series-on-nhibernate-and-fluent-nhibernate-ndash-part-2.aspx</link>
            <description>&lt;p&gt;Today the second part of my series on NHibernate and Fluent NHibernate went live. You can read it &lt;a href="http://dotnetslackers.com/articles/ado_net/Your-very-first-NHibernate-application-Part-2.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Summary &lt;/h3&gt;
&lt;p&gt;In part 2 of the article series I have continued to implement the remaining part of the domain which I had introduced in the &lt;a href="http://dotnetslackers.com/articles/ado_net/Your-very-first-NHibernate-application-Part-1.aspx"&gt;first part&lt;/a&gt;. I discuss the mapping of various forms of relations between different entities. For all mappings I have presented the code needed to verify the mappings. &lt;/p&gt;
&lt;p&gt;In part 3 of the article series I’ll show how one can further refactor and improve the mapping of the domain model. I’ll then discuss the usage of conventions and finally show how one can use the auto-mapping capabilities of &lt;strong&gt;Fluent NHibernate &lt;/strong&gt;to completely avoid the explicit mapping of entities.&lt;/p&gt;&lt;img src="http://blogs.hibernatingrhinos.com/nhibernate/aggbug/52.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>NHibernate's Answers</dc:creator>
            <guid>http://blogs.hibernatingrhinos.com/nhibernate/archive/2009/04/16/article-series-on-nhibernate-and-fluent-nhibernate-ndash-part-2.aspx</guid>
            <pubDate>Thu, 16 Apr 2009 12:30:10 GMT</pubDate>
            <wfw:comment>http://blogs.hibernatingrhinos.com/nhibernate/comments/52.aspx</wfw:comment>
            <comments>http://blogs.hibernatingrhinos.com/nhibernate/archive/2009/04/16/article-series-on-nhibernate-and-fluent-nhibernate-ndash-part-2.aspx#feedback</comments>
            <slash:comments>95</slash:comments>
            <wfw:commentRss>http://blogs.hibernatingrhinos.com/nhibernate/comments/commentRss/52.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Article series on NHibernate and Fluent NHibernate</title>
            <link>http://blogs.hibernatingrhinos.com/nhibernate/archive/2009/04/08/article-series-on-nhibernate-and-fluent-nhibernate.aspx</link>
            <description>Sorry for having been quiet such a long time. But I was really busy lately. I wrote several articles for journals and other non NHibernate related posts. But now the good news for all of you who like my tutorial like posts...&lt;br /&gt;
&lt;br /&gt;
I have been invited to write a series of articles on &lt;a href="http://www.nhforge.org/"&gt;NHibernate&lt;/a&gt; and &lt;a href="http://code.google.com/p/fluent-nhibernate/"&gt;Fluent NHibernate&lt;/a&gt; on &lt;a title="http://dotnetslackers.com" href="http://dotnetslackers.com/"&gt;http://dotnetslackers.com&lt;/a&gt;.&lt;br /&gt;
&lt;p&gt;The first part of this series has just been published. I invite you to read  it &lt;a href="http://dotnetslackers.com/articles/ado_net/Your-very-first-NHibernate-application-Part-1.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In this series I start from grounds up and will explain to the readers how  easy it has become to write an &lt;strong&gt;NHibernate&lt;/strong&gt; based application  since &lt;strong&gt;Fluent NHibernate&lt;/strong&gt; is available. I’ll explain the explicit  mapping with the fluent syntax as well as the auto-mapping that &lt;strong&gt;Fluent  NH&lt;/strong&gt; offers.&lt;/p&gt;
&lt;p&gt;This is a total overhaul compared to my &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx"&gt;first introduction&lt;/a&gt; to NHibernate of last year which is still the most popular post of this blog... ;-)&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Enjoy.&lt;br /&gt;
&lt;/p&gt;&lt;img src="http://blogs.hibernatingrhinos.com/nhibernate/aggbug/51.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>NHibernate's Answers</dc:creator>
            <guid>http://blogs.hibernatingrhinos.com/nhibernate/archive/2009/04/08/article-series-on-nhibernate-and-fluent-nhibernate.aspx</guid>
            <pubDate>Thu, 09 Apr 2009 00:04:51 GMT</pubDate>
            <wfw:comment>http://blogs.hibernatingrhinos.com/nhibernate/comments/51.aspx</wfw:comment>
            <comments>http://blogs.hibernatingrhinos.com/nhibernate/archive/2009/04/08/article-series-on-nhibernate-and-fluent-nhibernate.aspx#feedback</comments>
            <slash:comments>89</slash:comments>
            <wfw:commentRss>http://blogs.hibernatingrhinos.com/nhibernate/comments/commentRss/51.aspx</wfw:commentRss>
        </item>
        <item>
            <title>NHibernate and Castle Active Record (Part 1)</title>
            <link>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/26/nhibernate-and-castle-active-record-part-1.aspx</link>
            <description>&lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;The &lt;b&gt;Castle ActiveRecord&lt;/b&gt; project is an implementation of the &lt;a href="http://en.wikipedia.org/wiki/Active_record"&gt;ActiveRecord pattern&lt;/a&gt; for .NET. The ActiveRecord pattern consists on instance properties representing a record in the database, instance methods acting on that specific record and static methods acting on all records. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Castle ActiveRecord&lt;/b&gt; is built on top of &lt;a href="http://www.nhibernate.org/"&gt;NHibernate&lt;/a&gt;, but its attribute-based mapping free the developer of writing XML for database-to-object mapping, which is needed when using NHibernate directly.&lt;/p&gt;  &lt;p&gt;You can find the home page of the &lt;strong&gt;Castle&lt;/strong&gt; project &lt;a href="http://www.castleproject.org/"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;How will we use it?&lt;/h2&gt;  &lt;p&gt;My intent is not to implement the &lt;a href="http://en.wikipedia.org/wiki/Active_record"&gt;ActiveRecord pattern&lt;/a&gt; but rather use ActiveRecord&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;as an alternative way to define the &lt;a href="http://en.wikipedia.org/wiki/Object-relational_mapping"&gt;mapping&lt;/a&gt; between my domain objects and the relational database. &lt;/li&gt;    &lt;li&gt;to simplify the initialization of NHibernate (I'm not so sure about this...) &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In my previous posts (&lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx"&gt;here&lt;/a&gt; and &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/03/lazy-loading---eager-loading.aspx"&gt;here&lt;/a&gt;) I have shown you how to define the mapping between domain objects and database tables by writing XML documents. Active Record allows me to decorate my domain objects with attributes which define the mapping instead of (hand-) coding XML documents.&lt;/p&gt;  &lt;h2&gt;Downloading and compiling the Castle Active Record Trunk&lt;/h2&gt;  &lt;p&gt;If you have never downloaded and compiled OSS software from a SVN repository before please refer to my previous post about &lt;em&gt;preparing your system for NHibernate&lt;/em&gt; which you can find &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/03/31/prepare-your-system-for-nhibernate.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I assume you have TortoiseSVN installed as your SVN client.&lt;/p&gt;  &lt;p&gt;Make a new sub-folder called 'Castle' in your OSS folder (e.g. m:\dev\OSS\Castle). Right click on the folder an select 'SVN Checkout...'. Enter the URL '&lt;a href="http://svn.castleproject.org:8080/svn/castle/trunk/"&gt;http://svn.castleproject.org:8080/svn/castle/trunk/&lt;/a&gt;' in the &lt;strong&gt;Checkout&lt;/strong&gt; dialog and press OK. The Castle stack will be downloaded. Depending on the bandwidth of your Internet connection this may take a while. The whole Castle stack contains more software than we need at the moment but let's just download all and ignore the parts we don't need. The whole download is around 21 MB.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="363" alt="image" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/image_thumb.png" width="566" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;When the download is finished you can compile the Castle stack. This is an automated process. &lt;/p&gt;  &lt;h3&gt;Unit Tests during the build process&lt;/h3&gt;  &lt;p&gt;During the build a lot of unit tests will be executed. For this we either need NUnit or MbUnit on our system. If you don't  have it you can e.g. download NUnit from &lt;a href="http://www.nunit.org/index.php?p=download"&gt;here&lt;/a&gt;. Download just the zip file containing the binaries for .NET 2.0 (at the time of this writing it's the file 'NUnit-2.4.7-net-2.0.zip'). Extract the binaries into a sub-folder of your OSS directory (e.g. m:\dev\OSS\nunit).&lt;/p&gt;  &lt;h3&gt;Building the Castle Stack&lt;/h3&gt;  &lt;p&gt;Open a command console and navigate to the directory where you have downloaded Castle (e.g. m\dev\OSS\Castle). Assuming that NAnt is also installed in the OSS directory enter the following command&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;..\NAnt\bin\nant.exe -D:nunit-console=&amp;lt;path to nunit-console.exe&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;where at the place of &lt;strong&gt;&amp;lt;path to nunit-console.exe&amp;gt;&lt;/strong&gt; you enter the path where you have unzipped/installed &lt;strong&gt;NUnit&lt;/strong&gt;. In our case this is &lt;strong&gt;'m:\dev\OSS\NUnit\bin\NUnit-Console.exe'&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;Now the whole Castle stack is compiled and all tests are executed. This can take a while. On my machine it took about 2.5 minutes. The overall build may fail but still the assemblies are created (the reason of the overall failure might be that some of the Unit test fail. Remember that we are on the Trunk and this is under constant development. Sometimes some of the tests may thus fail.). The result on my machine was as follows&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="266" alt="image" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/image_thumb_2.png" width="501" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After building the Castle stack you should find a new sub-folder &lt;strong&gt;'build'&lt;/strong&gt; in the &lt;strong&gt;Castle&lt;/strong&gt; folder.&lt;/p&gt;  &lt;h2&gt;Using Active Record&lt;/h2&gt;  &lt;h3&gt;External dependencies of the Solution&lt;/h3&gt;  &lt;p&gt;For an introduction on how to setup a new solution please refer to this &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/06/how-to-setup-a-new-solution.aspx"&gt;post&lt;/a&gt;. You can now copy all the necessary external assemblies on which the solution depends into the SharedLibs folder in your solution tree. You should copy all files (including NHibernate) from the &lt;strong&gt;build&lt;/strong&gt; folder of &lt;strong&gt;Castle&lt;/strong&gt; which was created during the build process described above.  For this solution you need at least the following files&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/image_10.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="413" alt="image" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/image_thumb_4.png" width="236" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The sql*.dll are in the folder since we are using SQL Server Compact edition as a database. If you have read the previous posts about using NHibernate (e.g. &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx"&gt;here&lt;/a&gt; and &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/03/lazy-loading---eager-loading.aspx"&gt;here&lt;/a&gt;) the only new files are &lt;strong&gt;Castle.ActiveRecord.dll&lt;/strong&gt; and &lt;strong&gt;Castle.Components.Validator.dll&lt;/strong&gt;.&lt;/p&gt;  &lt;h3&gt;The Domain Model and the Mapping&lt;/h3&gt;  &lt;p&gt;To have a good comparison let's take the same domain model as in &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/03/lazy-loading---eager-loading.aspx"&gt;this&lt;/a&gt; post. Below is the class diagram of the domain.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="430" alt="image" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/image_thumb_1.png" width="533" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now instead of writing a domain class and then a XML mapping document we now only write the domain class and decorate it and its members with attributes. During initialization &lt;strong&gt;ActiveRecord&lt;/strong&gt; will automatically generate the XML mapping documents for us which NHibernate requires for the object-relational mapping.&lt;/p&gt;  &lt;p&gt;When using attributes the Order class will look like this&lt;/p&gt;  &lt;div&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;using&lt;/span&gt; System;&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;using&lt;/span&gt; Castle.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: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; Iesi.Collections.Generic;&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;using&lt;/span&gt; NHibernateAndActiveRecord.Domain;&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;namespace&lt;/span&gt; NHibernateAndActiveRecord.Domain&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;    [ActiveRecord(Table = &lt;span style="color: #006080"&gt;"Orders"&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;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Order&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; Order()&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;            OrderLines = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HashedSet&amp;lt;OrderLine&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;/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.Guid)]&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;virtual&lt;/span&gt; Guid 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; &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;        [BelongsTo(NotNull = &lt;span style="color: #0000ff"&gt;true&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; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; Customer Customer { 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; &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; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; OrderNumber { 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;/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;virtual&lt;/span&gt; DateTime OrderDate { 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; &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;        [HasMany(Table = &lt;span style="color: #006080"&gt;"OrderLine"&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;                 ColumnKey = &lt;span style="color: #006080"&gt;"OrderId"&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;                 Cascade = ManyRelationCascadeEnum.AllDeleteOrphan)]&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;virtual&lt;/span&gt; ISet&amp;lt;OrderLine&amp;gt; OrderLines { 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;/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;compared to a typical XML mapping document this is much more wrist friendly, isn't it. Some people also argue that attributes help to document the code, since I can immediately see e.g. which is the primary key and which property values should never be null, etc. I do not have to consult another file but can just look at the domain class to have the "full" picture. On the other hand the attributes also "clutter" my nice code and I partially violate the &lt;a href="http://en.wikipedia.org/wiki/SOC"&gt;SoC&lt;/a&gt; pattern since mapping is not part of the domain in a DDD world.&lt;/p&gt;

&lt;p&gt;Now let's look at the &lt;strong&gt;OrderLine&lt;/strong&gt; class&lt;/p&gt;

&lt;div&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;using&lt;/span&gt; System;&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;using&lt;/span&gt; Castle.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: 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;namespace&lt;/span&gt; NHibernateAndActiveRecord.Domain&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;    [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: 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; OrderLine&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;        [PrimaryKey(Generator = PrimaryKeyType.Guid)]&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;virtual&lt;/span&gt; Guid 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: 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;        [Property(NotNull = &lt;span style="color: #0000ff"&gt;true&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;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Amount { 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;/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(NotNull = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, Length = 50)]&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;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; ProductName { 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;    }&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;Here I have defined that Amount and &lt;strong&gt;ProductName&lt;/strong&gt; cannot be null (this will be used for the generation of the database schema - there will be not null constraints on the corresponding table column). I also have defined that the maximal length of the &lt;strong&gt;ProductName&lt;/strong&gt; cannot exceed 50 characters (also used for schema generation).&lt;/p&gt;

&lt;p&gt;Finally the &lt;strong&gt;Customer &lt;/strong&gt;class&lt;/p&gt;

&lt;div&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;using&lt;/span&gt; System;&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;using&lt;/span&gt; Castle.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: 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;namespace&lt;/span&gt; NHibernateAndActiveRecord.Domain&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;    [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: 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; Customer&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;        [PrimaryKey(Generator = PrimaryKeyType.Guid)]&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;virtual&lt;/span&gt; Guid 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: 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;        [Property(NotNull = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, Length = 50)]&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;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; CompanyName { 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;/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's it. Our domain and mapping is complete. We can now write our tests similar to the once we used in this &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/03/lazy-loading---eager-loading.aspx"&gt;post&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Unit Tests&lt;/h3&gt;

&lt;p&gt;Add an xml document to your test project and call it ActiveRecord.cfg.xml (similar to what you do when you ONLY use NHibernate). Add the following content to the file&lt;/p&gt;

&lt;div&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;&amp;lt;?&lt;/span&gt;&lt;span style="color: #800000"&gt;xml&lt;/span&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="1.0"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="utf-8"&lt;/span&gt; ?&lt;span style="color: #0000ff"&gt;&amp;gt;&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;/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;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;activerecord&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&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;/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;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;config&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&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;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="connection.provider"&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;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="NHibernate.Connection.DriverConnectionProvider"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&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;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="dialect"&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;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="NHibernate.Dialect.MsSqlCeDialect"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&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;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="connection.driver_class"&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;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="NHibernate.Driver.SqlServerCeDriver"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&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;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="connection.connection_string"&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;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Data Source=SampleDb.sdf"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&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;/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;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="show_sql"&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: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="true"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&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;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;config&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&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;/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;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;activerecord&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Set the &lt;strong&gt;Copy to Output Directory&lt;/strong&gt; to &lt;strong&gt;Copy always&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: we are using SQL server compact edition in this case (the second, third and fourth entry in the XML are specific for this database).&lt;/p&gt;

&lt;p&gt;Add an new item of type &lt;strong&gt;LocalDatabase&lt;/strong&gt; to the test project and call it &lt;strong&gt;SampleDb.sdf&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Still in the test project add a reference to the System.Data.SqlServerCe.dll in the SharedLibs folder. This assembly contains the ado.net driver for SQL server compact edition.&lt;/p&gt;

&lt;p&gt;Open the properties page of the test project and add the following command in the "&lt;strong&gt;Pre-build event command line"&lt;/strong&gt; text box&lt;/p&gt;

&lt;p&gt;&lt;font face="Courier New"&gt;copy $(ProjectDir)..\..\SharedLibs\sqlce*.dll $(ProjectDir)$(OutDir)&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;This command copies all the SQL server CE files from the SharedLibs folder to the target folder of the test project. Note: this is important, otherwise the test will not run. Also note that this is only needed if you use SQL server CE.&lt;/p&gt;

&lt;p&gt;The first unit test we write will test whether we can successfully create the database schema or not. This is always a good test if your new to ActiveRecord. Add a new class CreateSchema_Fixture.cs to the test project and add the code below&lt;/p&gt;

&lt;div&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;using&lt;/span&gt; Castle.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;using&lt;/span&gt; Castle.ActiveRecord.Framework.Config;&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;using&lt;/span&gt; NHibernateAndActiveRecord.Domain;&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;using&lt;/span&gt; NUnit.Framework;&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;namespace&lt;/span&gt; NibernateAndActiveRecord.Tests&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;    [TestFixture]&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;class&lt;/span&gt; CreateSchema_Fixture&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;        [Test]&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;void&lt;/span&gt; Can_initialize_and_create_schema()&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;            var configurationSource = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlConfigurationSource(&lt;span style="color: #006080"&gt;"ActiveRecord.cfg.xml"&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;            ActiveRecordStarter.Initialize(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Customer).Assembly, configurationSource);&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;            ActiveRecordStarter.CreateSchema();&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;In the first line of the test we provide ActiveRecord with the necessary configuration info. In the second line we tell ActiveRecord to initialize itself (and NHibernate) with the given configuration info as well as the assembly in which the domain classes are implemented (and which also contains the mapping info since we use attributes). Then in the third line we create the schema. If there is already a schema in the db this will be deleted first.&lt;/p&gt;

&lt;p&gt;If you have done every thing right, then the test should succeed.&lt;/p&gt;

&lt;p&gt;Now we can continue to test our domain model. Let's first implement a base fixture class to free us from repeating code again and again. I suggest a class as follows&lt;/p&gt;

&lt;div&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;using&lt;/span&gt; Castle.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;using&lt;/span&gt; Castle.ActiveRecord.Framework.Config;&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;using&lt;/span&gt; NHibernateAndActiveRecord.Domain;&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;using&lt;/span&gt; NUnit.Framework;&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;namespace&lt;/span&gt; NibernateAndActiveRecord.Tests&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;    [TestFixture]&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;class&lt;/span&gt; TestFixtureBase&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;        [TestFixtureSetUp]&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;void&lt;/span&gt; TestFixtureSetUp()&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;            var configurationSource = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlConfigurationSource(&lt;span style="color: #006080"&gt;"ActiveRecord.cfg.xml"&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;            ActiveRecordStarter.Initialize(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Customer).Assembly, configurationSource);&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;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;        [SetUp]&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;void&lt;/span&gt; SetupContext()&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;            ActiveRecordStarter.CreateSchema();&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;            Before_each_test();&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;        [TearDown]&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;void&lt;/span&gt; TearDownContext()&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;            After_each_test();&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;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Before_each_test()&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;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;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; After_each_test()&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;This class is equivalent to the class presented in this &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/03/lazy-loading---eager-loading.aspx"&gt;post&lt;/a&gt; on NHibernate. Once for each test session I configure ActiveRecord (and implicitly NHibernate). Before each single test I recreate the database schema to avoid any side effects leaking from one test to another. I also provide virtual methods which can be overridden in the child classes to execute specific code before or after each test.&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;I have introduced &lt;strong&gt;Castle ActiveRecord&lt;/strong&gt; as an alternative way to use NHibernate. It's a layer on top of NHibernate and simplifies in many cases the usage of NHibernate. I have shown you how you can get the latest code from the source repository and compile it. I have then setup a simple domain model and defined a test fixture base class.&lt;/p&gt;

&lt;p&gt;I'll continue to implement the tests in part 2 of this series. So keep ready...&lt;/p&gt;

&lt;p&gt;Enjoy&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/Blog%20Signature%20Gabriel_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="21" alt="Blog Signature Gabriel" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/ActiveRecord_14F19/Blog%20Signature%20Gabriel_thumb.png" width="244" border="0" /&gt;&lt;/a&gt;. &lt;/p&gt;&lt;img src="http://blogs.hibernatingrhinos.com/nhibernate/aggbug/16.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>NHibernate's Answers</dc:creator>
            <guid>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/26/nhibernate-and-castle-active-record-part-1.aspx</guid>
            <pubDate>Sat, 26 Apr 2008 19:33:44 GMT</pubDate>
            <wfw:comment>http://blogs.hibernatingrhinos.com/nhibernate/comments/16.aspx</wfw:comment>
            <comments>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/26/nhibernate-and-castle-active-record-part-1.aspx#feedback</comments>
            <slash:comments>57</slash:comments>
            <wfw:commentRss>http://blogs.hibernatingrhinos.com/nhibernate/comments/commentRss/16.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How to setup a new solution</title>
            <link>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/06/how-to-setup-a-new-solution.aspx</link>
            <description>&lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;In this post I'll present a &lt;em&gt;possible&lt;/em&gt; setup for a .NET solution which respects (as much as possible) the following aspects, patterns and software engineering practices&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Continuous_integration"&gt;Continuous Integration&lt;/a&gt; (CI) &lt;/li&gt;    &lt;li&gt;Deploy often (--&amp;gt; see &lt;a href="http://en.wikipedia.org/wiki/Agile_development"&gt;Agile development&lt;/a&gt;) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://domaindrivendesign.org/"&gt;Domain Driven Design&lt;/a&gt; (DDD) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Test-driven_development"&gt;Test Driven Development&lt;/a&gt; (TDD) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;Separation of Concern&lt;/a&gt; (SoC) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In most of the samples presented in this blog I'll adhere to this kind of solution setup (e.g. &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx"&gt;here&lt;/a&gt; and &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/03/lazy-loading---eager-loading.aspx"&gt;here&lt;/a&gt;)!&lt;/p&gt;  &lt;p&gt;The solution should have as few external dependencies as possible. All external libraries (of course we don't count the .NET framework here) on which the solution is dependent should be (if possible) part of the solution tree. Then you can always (if you have your solution tree under source control -- &lt;strong&gt;and you definitely should&lt;/strong&gt;!) check out the complete solution tree on any machine (e.g. on the build server or on a new developer machine) and just build the solution and run the unit tests without any further manual intervention needed.&lt;/p&gt;  &lt;p&gt;Each project of the solution has a corresponding test project where you implement all your &lt;a href="http://en.wikipedia.org/wiki/Unit_test"&gt;unit tests&lt;/a&gt; (and/or &lt;a href="http://en.wikipedia.org/wiki/Integration_test"&gt;integration tests&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Acceptance_test"&gt;acceptance tests&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Stress_test"&gt;stress tests&lt;/a&gt;, etc.) for the respective project. So, if you have a project in the solution called &lt;strong&gt;Domain&lt;/strong&gt; you should automatically have a additional project in the solution which you might call &lt;strong&gt;Domain.Tests&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Separation of Concern (SoC) suggests us to split the whole solution into several projects. I often have at least 3 types of projects. In a typical WinForms based application these might be&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Domain&lt;/strong&gt; - contains the domain model with it's domain entities, services, factories and repository interfaces &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DataLayer&lt;/strong&gt; - contains the NHibernate XML mapping files and the implementation of the repositories &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Application&lt;/strong&gt; (or PresentationLayer) - contains the application or presentation logic, the application shell, the views, presenters and/or application controllers &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Of course each of those projects has a corresponding Tests project.&lt;/p&gt;  &lt;p&gt;Depending on the complexity of the solution there might be even more projects.&lt;/p&gt;  &lt;p&gt;Normally I have a &lt;strong&gt;Dev&lt;/strong&gt; folder on one of my (local) hard disks. The Dev folder has at least two sub-folders &lt;strong&gt;OSS&lt;/strong&gt; and &lt;strong&gt;Projects&lt;/strong&gt;. In the OSS folder I have a copy of the source or binaries of all open source software I use in my projects. As you can see below I have downloaded Castle, NAnt, NHibernate, NUnit and the Rhino Tools.&lt;/p&gt;  &lt;p&gt; &lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/Howtosetupanewsolution_12F45/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="182" alt="image" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/Howtosetupanewsolution_12F45/image_thumb.png" width="158" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The green check marks on Castle, NHibernate and Rhino Tools show that these folders are under source control (&lt;a href="http://subversion.tigris.org/"&gt;SVN&lt;/a&gt; in this case) and that I have the most recent version of the source.&lt;/p&gt;  &lt;p&gt;In the sub-folder Projects I put all the solutions we develop for our customers.&lt;/p&gt;  &lt;h2&gt;Sample Solution Structure&lt;/h2&gt;  &lt;p&gt;Now let's have a look at the structure of a sample solution. Let's assume that it's a WinForms based application and call the solution &lt;strong&gt;DemoSolution&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/Howtosetupanewsolution_12F45/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="200" alt="image" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/Howtosetupanewsolution_12F45/image_thumb_2.png" width="178" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In the Projects folder I create a sub-folder with the same name as the solution, in this case DemoSolution. In this solution folder I create at least the two sub-folders &lt;strong&gt;SharedLibs&lt;/strong&gt; and &lt;strong&gt;src&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;The folder &lt;strong&gt;SharedLibs&lt;/strong&gt; contains all the external assemblies my solution depends on (e.g. NHibernate, Castle, 3rd party WinForm Controls, etc.). The content of the &lt;strong&gt;SharedLibs&lt;/strong&gt; folder varies depending on the needs of the solution. In the sample solution I have presented &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx"&gt;here&lt;/a&gt; we have the following files in this folder&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/Howtosetupanewsolution_12F45/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="341" alt="image" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/Howtosetupanewsolution_12F45/image_thumb_3.png" width="208" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; Each project of the solution which references one or several of those external libraries points to this &lt;strong&gt;SharedLibs&lt;/strong&gt; folder! That is: never reference an assembly from the GAC (except the .NET libraries of course).&lt;/p&gt;  &lt;p&gt;The folder &lt;strong&gt;src&lt;/strong&gt; on the other hand contains our own source code for the solution. The Visual Studio solution file &lt;strong&gt;*.sln&lt;/strong&gt; I put directly in the &lt;strong&gt;src&lt;/strong&gt; folder. Normally the VS solution has the same name as the solution folder (in this case DemoSolution.sln). For each project of the VS solution I have one sub-folder. In this case we have 6 projects in the solution, three of them containing the code which makes up our application and the other 3 projects containing the code of the corresponding (unit-) tests.&lt;/p&gt;  &lt;h2&gt;Summary&lt;/h2&gt;  &lt;p&gt;I have presented you a possible structure for a solution you develop. This structure tries to satisfy various requirements implied by commonly used patterns and software engineering practices.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/Howtosetupanewsolution_12F45/Blog%20Signature%20Gabriel_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="21" alt="Blog Signature Gabriel" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/Howtosetupanewsolution_12F45/Blog%20Signature%20Gabriel_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; .&lt;/p&gt;&lt;img src="http://blogs.hibernatingrhinos.com/nhibernate/aggbug/9.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>NHibernate's Answers</dc:creator>
            <guid>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/06/how-to-setup-a-new-solution.aspx</guid>
            <pubDate>Sun, 06 Apr 2008 20:18:49 GMT</pubDate>
            <wfw:comment>http://blogs.hibernatingrhinos.com/nhibernate/comments/9.aspx</wfw:comment>
            <comments>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/06/how-to-setup-a-new-solution.aspx#feedback</comments>
            <slash:comments>57</slash:comments>
            <wfw:commentRss>http://blogs.hibernatingrhinos.com/nhibernate/comments/commentRss/9.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Your first NHibernate based application</title>
            <link>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx</link>
            <description>&lt;p&gt;In a &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/03/31/prepare-your-system-for-nhibernate.aspx"&gt;previous article&lt;/a&gt; I showed how to setup a developer machine to start using NHibernate as an ORM tool during the development of an application. I advocated a domain driven design (DDD) approach and a test driven development (TDD) style. This is the second article in a series of introductory chapters.&lt;/p&gt;
&lt;h3&gt;Define the Domain&lt;/h3&gt;
&lt;p&gt;Lets start by defining a very simple domain. For the moment it consists of one entity called &lt;strong&gt;Product&lt;/strong&gt;. The product has 3 properties Name, Category and Discontinued.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_4.png"&gt;&lt;img height="179" width="181" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_1.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Add a folder Domain to the FirstSample project of your solution. Add a new class &lt;strong&gt;Product.cs&lt;/strong&gt; to this folder. The code is very simple and uses automatic properties (a feature of the new C# 3.0 compiler)&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; FirstSolution.Domain&lt;/pre&gt;
&lt;pre&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Product&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Category { get; set; }&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Discontinued { get; set; }&lt;/pre&gt;
&lt;pre&gt;    }&lt;/pre&gt;
&lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;Now we want to be able to persist instances of this entity in a (relational) database. We have chosen &lt;strong&gt;NHibernate&lt;/strong&gt; for this task. An instance of an entity in the domain corresponds to a &lt;strong&gt;row in a table&lt;/strong&gt; in the database. So we have to define a mapping between the entity and the corresponding table in the database. This mapping can be done either by defining a mapping file (an xml-document) or by decorating the entity with attributes. I'll start with the mapping file.&lt;/p&gt;
&lt;h3&gt;Define the Mapping&lt;/h3&gt;
&lt;p&gt;Create a folder &lt;strong&gt;Mappings&lt;/strong&gt; in the FirstSample project. Add a new xml-document to this folder and call it &lt;strong&gt;Person.hbm.xml&lt;/strong&gt;. Please note the "hbm" part of the file name. This is a convention used by NHibernate to automatically recognize the file as a mapping file. Define "Embedded Resource" as &lt;strong&gt;Build Action&lt;/strong&gt; for this xml file. &lt;/p&gt;
&lt;p&gt;In the Windows Explorer locate the nhibernate-mapping.xsd in the src folder of NHibernate and copy it to your SharedLibs folder. We can now use this xml schema definition file when defining our mapping files. VS will then provide intellisense and validation when editing an xml mapping document.&lt;/p&gt;
&lt;p&gt;Back in VS add the schema to the Product.hbm.xml file&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_6.png"&gt;&lt;img height="207" width="499" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_2.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Let's start now. Each mapping file has to define a &amp;lt;hibernate-mapping&amp;gt; root node&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;="1.0"&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;="utf-8"&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;hibernate-mapping&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="urn:nhibernate-mapping-2.2"&lt;/span&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;                   &lt;span class="attr"&gt;assembly&lt;/span&gt;&lt;span class="kwrd"&gt;="FirstSolution"&lt;/span&gt; &lt;/pre&gt;
&lt;pre&gt;                   &lt;span class="attr"&gt;namespace&lt;/span&gt;&lt;span class="kwrd"&gt;="FirstSolution.Domain"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;  &lt;span class="rem"&gt;&amp;lt;!-- more mapping info here --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;  &lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;hibernate-mapping&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;In a mapping file when referencing a domain class you always have to provide the fully qualified name of the class (e.g. FirstSample.Domain.Product, FirstSample). To make the xml less verbose you can define the assembly name (in which the domain classes are implemented and the namespace of the domain classes in the two attributes &lt;strong&gt;assembly&lt;/strong&gt; and &lt;strong&gt;namespace&lt;/strong&gt; of the root node. It's similar to the &lt;strong&gt;using&lt;/strong&gt; statement in C#.&lt;/p&gt;
&lt;p&gt;Now we have to first define a &lt;strong&gt;primary key&lt;/strong&gt; for the product entity. Technically we could take the property &lt;strong&gt;Name&lt;/strong&gt; of the product since this property must be defined and has to be unique. But it is common to use a surrogate key instead. For thus we add a property to our entity and call it &lt;strong&gt;Id&lt;/strong&gt;. We use &lt;strong&gt;Guid&lt;/strong&gt; as the type of the Id but it can as well be an int or a long.&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; FirstSolution.Domain&lt;/pre&gt;
&lt;pre&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Product&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Guid Id { get; set; }&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Category { get; set; }&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Discontinued { get; set; }&lt;/pre&gt;
&lt;pre class="alt"&gt;    }&lt;/pre&gt;
&lt;pre&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;The complete mapping file&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;="1.0"&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;="utf-8"&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;hibernate-mapping&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="urn:nhibernate-mapping-2.2"&lt;/span&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;                   &lt;span class="attr"&gt;assembly&lt;/span&gt;&lt;span class="kwrd"&gt;="FirstSolution"&lt;/span&gt; &lt;/pre&gt;
&lt;pre&gt;                   &lt;span class="attr"&gt;namespace&lt;/span&gt;&lt;span class="kwrd"&gt;="FirstSolution.Domain"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;  &lt;/pre&gt;
&lt;pre&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;class&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Product"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;id&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Id"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;generator&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="guid"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Name"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Category"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Discontinued"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;  &lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;hibernate-mapping&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;NHibernate doesn't get in our way such as that it defines many reasonable defaults. So if you don't provide a column name for a property explicitly it will name the column according to the property. Or NHibernate can automatically infer the name of the table or the type of the column from the class definition. As a consequence my xml mapping file is not cluttered with redundant information. Please refer to the online documentation for more detailed explanation of the mapping. You can find it &lt;a href="http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/mapping.html"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Your solution explorer should look like this now (&lt;strong&gt;Domain.cd&lt;/strong&gt; contains the class diagram of our simple domain)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_8.png"&gt;&lt;img height="310" width="313" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_3.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;h3&gt;Configure NHibernate&lt;/h3&gt;
&lt;p&gt;We now have to tell NHibernate which database product we want to use and provide it the connection details in form of a connection string. NHibernate supports many many database products!&lt;/p&gt;
&lt;p&gt;Add a new xml file to the FirstSolution project and call it hibernate.cfg.xml. Set its property "&lt;strong&gt;Copy to Output&lt;/strong&gt;" to "&lt;strong&gt;Copy always&lt;/strong&gt;". Since we are using SQL Server Compact Edition in this first sample enter the following information into the xml file&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;="1.0"&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;="utf-8"&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;hibernate-configuration&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="urn:nhibernate-configuration-2.2"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;session-factory&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="connection.provider"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;NHibernate.Connection.DriverConnectionProvider&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="dialect"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;NHibernate.Dialect.MsSqlCeDialect&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="connection.driver_class"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;NHibernate.Driver.SqlServerCeDriver&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="connection.connection_string"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Data Source=FirstSample.sdf&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;    &lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="show_sql"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;true&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;session-factory&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;hibernate-configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;With this configuration file we tell NHibernate that we want to use MS SQL Server Compact Edition as our target database and that the name of the database shall be FirstSample.sdf (=connection string). We have also defined that we want to see the &lt;strong&gt;SQL&lt;/strong&gt; NHibernate generates and sends to the datbase (highly recommended for debugging purposes during development). Double check that you have no typos in the code!&lt;/p&gt;
&lt;p&gt;Add an empty database called &lt;strong&gt;FirstSample.sdf&lt;/strong&gt; to the FirstSample project (choose &lt;strong&gt;Local Database&lt;/strong&gt; as template)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_10.png"&gt;&lt;img height="388" width="644" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_4.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Click Add and ignore the DataSet creation wizard (just hit Cancel).&lt;/p&gt;
&lt;h3&gt;Test the Setup&lt;/h3&gt;
&lt;p&gt; It's now time to test our setup. First verify that you have the following files in your SharedLibs folder&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_12.png"&gt;&lt;img height="484" width="251" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_5.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The last 8 files you can find in the "&lt;strong&gt;Microsoft SQL Server Compact Edition&lt;/strong&gt;" directory in your Programs folder.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_14.png"&gt;&lt;img height="484" width="585" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_6.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Note: the &lt;strong&gt;System.Data.SqlServerCe.dll&lt;/strong&gt; is located in the sub-folder &lt;strong&gt;Desktop&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;All other files can be found in the NHibernate folder&lt;/p&gt;
&lt;p&gt;Add a reference to the FirstSample project in your test project. Additionally add references to NHibernate.dll, nunit.framework.dll and Systm.Data.SqlServerCe.dll (remember to reference the files located in the SharedLibs folder!). Pay attention to set the property "&lt;strong&gt;Copy Local&lt;/strong&gt;" to &lt;strong&gt;true&lt;/strong&gt; for the assembly System.Data.SqlServerCe.dll since by default it is set to false!&lt;/p&gt;
&lt;p&gt;Add a class called &lt;strong&gt;GenerateSchema_Fixture&lt;/strong&gt; to your test project. Your test project should now look like this&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_16.png"&gt;&lt;img height="484" width="325" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_7.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;We further need the 7 files sqce*.dll in the output directory. We can do this by using a post-build event in VS. Enter the following command in the "Post-build event command line"&lt;/p&gt;
&lt;p&gt;copy $(ProjectDir)..\..\SharedLibs\sqlce*.dll $(ProjectDir)$(OutDir)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_20.png"&gt;&lt;img height="399" width="597" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_9.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Now add the following code to the GenerateSchema_Fixture file&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; FirstSolution.Domain;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; NHibernate.Cfg;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; NHibernate.Tool.hbm2ddl;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; NUnit.Framework;&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; FirstSolution.Tests&lt;/pre&gt;
&lt;pre class="alt"&gt;{&lt;/pre&gt;
&lt;pre&gt;    [TestFixture]&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; GenerateSchema_Fixture&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        [Test]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Can_generate_schema()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            var cfg = &lt;span class="kwrd"&gt;new&lt;/span&gt; Configuration();&lt;/pre&gt;
&lt;pre class="alt"&gt;            cfg.Configure();&lt;/pre&gt;
&lt;pre&gt;            cfg.AddAssembly(&lt;span class="kwrd"&gt;typeof&lt;/span&gt; (Product).Assembly);&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; SchemaExport(cfg).Execute(&lt;span class="kwrd"&gt;false&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;pre&gt;    }&lt;/pre&gt;
&lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;The first line of the test method creates a new instance of the NHibernate configuration class. This class is used to configure NHibernate. In the second line we tell NHibernate to configure itself. NHibernate will look out for configuration information since we do not provide any information here in the test method. So NHibernate will search for a file called &lt;strong&gt;hibernate.cfg.xml&lt;/strong&gt; in the output directory. That's exactly what we want since we have defined our settings in this file.&lt;/p&gt;
&lt;p&gt;In the third line of the code we tell NHibernate that it can find mapping information in the assembly which contains also the class Product. At the time being it will only find one such file (Product.hbm.xml) as an embedded resource.&lt;/p&gt;
&lt;p&gt;The fourth line of code uses the SchemaExport helper class of NHibernate to auto-"magically" generate the schema in the database for us.&lt;/p&gt;
&lt;p&gt;Note: with this test method we do &lt;strong&gt;NOT&lt;/strong&gt; want to find out whether NHibernate does its job correctly (you can be sure it does) but rater whether we have setup our system correctly.&lt;/p&gt;
&lt;p&gt;If you have &lt;a href="http://www.testdriven.net/"&gt;TestDriven.Net&lt;/a&gt; installed you can now just right click inside the test method and choose "&lt;strong&gt;Run Test(s)&lt;/strong&gt;" to execute the test.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_18.png"&gt;&lt;img height="255" width="499" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_8.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;If every thing is ok you should see the following result in the output window&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_22.png"&gt;&lt;img height="160" width="473" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_10.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;If you have &lt;a href="http://www.jetbrains.com/resharper/"&gt;ReSharper&lt;/a&gt; installed you can just start the test by clicking the yellow-green circle on the left border and choose &lt;strong&gt;Run&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_24.png"&gt;&lt;img height="189" width="364" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_11.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The result is as follows&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_26.png"&gt;&lt;img height="283" width="445" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_12.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;h3&gt;In case of Problems&lt;/h3&gt;
&lt;p&gt;If your test fails double check that you find the following files in your target directory (that is: m:dev\projects\FirstSolution\src\FirstSolution.Tests\bin\debug)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_28.png"&gt;&lt;img height="484" width="278" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_13.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Double check also if you have no typos in the NHibernate configuration file (hibernate.cfg.xml) or in the mapping file (Product.hbm.xml). Finally check whether you have set the "&lt;strong&gt;Build Action&lt;/strong&gt;" of the mapping file (Product.hbm.xml) to "&lt;strong&gt;Embedded Resource&lt;/strong&gt;". Only continue if the test succeeds.&lt;/p&gt;
&lt;h3&gt;Our first CRUD operations&lt;/h3&gt;
&lt;p&gt;Now obviously our system is ready to start. We have successfully implemented our Domain, defined the mapping files and configured NHibernate. Finally we have used NHibernate to automatically generate the database schema from our Domain (and our mapping files).&lt;/p&gt;
&lt;p&gt;In the spirit of DDD (see e.g. &lt;a href="http://domaindrivendesign.org/books/"&gt;Domain Driven Design&lt;/a&gt; by Eric Evans) we define a repository for all crud operations (create, read, update and delete). The repository interface is part of the domain where as the implementation is not! The implementation is infrastructure specific. We want to keep our domain persistence ignorant (PI).&lt;/p&gt;
&lt;p&gt;Add a new interface to the domain folder of our FirstSolution project. Call it IProductRepository. Let's define the following interface&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; FirstSolution.Domain&lt;/pre&gt;
&lt;pre class="alt"&gt;{&lt;/pre&gt;
&lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IProductRepository&lt;/pre&gt;
&lt;pre class="alt"&gt;    {&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; Add(Product product);&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; Update(Product product);&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; Remove(Product product);&lt;/pre&gt;
&lt;pre class="alt"&gt;        Product GetById(Guid productId);&lt;/pre&gt;
&lt;pre&gt;        Product GetByName(&lt;span class="kwrd"&gt;string&lt;/span&gt; name);&lt;/pre&gt;
&lt;pre class="alt"&gt;        ICollection&amp;lt;Product&amp;gt; GetByCategory(&lt;span class="kwrd"&gt;string&lt;/span&gt; category);&lt;/pre&gt;
&lt;pre&gt;    }&lt;/pre&gt;
&lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;Add a class ProductRepository_Fixture to the test project of the solution and add the following code&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;    [TestFixture]&lt;/pre&gt;
&lt;pre&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ProductRepository_Fixture&lt;/pre&gt;
&lt;pre class="alt"&gt;    {&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; ISessionFactory _sessionFactory;&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; Configuration _configuration;&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;        [TestFixtureSetUp]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; TestFixtureSetUp()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            _configuration = &lt;span class="kwrd"&gt;new&lt;/span&gt; Configuration();&lt;/pre&gt;
&lt;pre class="alt"&gt;            _configuration.Configure();&lt;/pre&gt;
&lt;pre&gt;            _configuration.AddAssembly(&lt;span class="kwrd"&gt;typeof&lt;/span&gt; (Product).Assembly);&lt;/pre&gt;
&lt;pre class="alt"&gt;            _sessionFactory = _configuration.BuildSessionFactory();&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;pre class="alt"&gt;    }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;In the fourth line of the method TestFixtureSetUp we create a session factory. This is an expensive process and should thus be executed only once. That's the reason why I put it into this method which is only executed once during a test cicle.
&lt;p&gt;To keep our test methods side effect free we re-create our database schema before the execution of each test method. Thus we add the following method&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        [SetUp]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetupContext()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; SchemaExport(_configuration).Execute(&lt;span class="kwrd"&gt;false&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;And now we can implement the test method to add a new product instance to the database. Start by adding a new folder called Repositories to your &lt;strong&gt;FirstSolution&lt;/strong&gt; project. Add a class &lt;strong&gt;ProductRepository&lt;/strong&gt; to this folder. Make the &lt;strong&gt;ProductRepository&lt;/strong&gt; inherit from the interface &lt;strong&gt;IProductRepository&lt;/strong&gt;.
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; FirstSolution.Domain;&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; FirstSolution.Repositories&lt;/pre&gt;
&lt;pre&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ProductRepository : IProductRepository&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Add(Product product)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Update(Product product)&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Remove(Product product)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Product GetById(Guid productId)&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Product GetByName(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; ICollection&amp;lt;Product&amp;gt; GetByCategory(&lt;span class="kwrd"&gt;string&lt;/span&gt; category)&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;pre&gt;    }&lt;/pre&gt;
&lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;h4&gt;Manipulating Data&lt;/h4&gt;
&lt;p&gt;Now go back to the ProductRepository_Fixture test class and implement the first test method&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        [Test]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Can_add_new_product()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            var product = &lt;span class="kwrd"&gt;new&lt;/span&gt; Product {Name = &lt;span class="str"&gt;"Apple"&lt;/span&gt;, Category = &lt;span class="str"&gt;"Fruits"&lt;/span&gt;};&lt;/pre&gt;
&lt;pre class="alt"&gt;            IProductRepository repository = &lt;span class="kwrd"&gt;new&lt;/span&gt; ProductRepository();&lt;/pre&gt;
&lt;pre&gt;            repository.Add(product);&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;The first run of the test method will fail since we have not yet implemented the &lt;strong&gt;Add&lt;/strong&gt; method in the repository class. Let's do it. &lt;strong&gt;But wait&lt;/strong&gt;, we have to define a little helper class first which provides us session objects on demand.&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; FirstSolution.Domain;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; NHibernate;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; NHibernate.Cfg;&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; FirstSolution.Repositories&lt;/pre&gt;
&lt;pre&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; NHibernateHelper&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; ISessionFactory _sessionFactory;&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; ISessionFactory SessionFactory&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            get&lt;/pre&gt;
&lt;pre&gt;            {&lt;/pre&gt;
&lt;pre class="alt"&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt;(_sessionFactory == &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre&gt;                {&lt;/pre&gt;
&lt;pre class="alt"&gt;                    var configuration = &lt;span class="kwrd"&gt;new&lt;/span&gt; Configuration();&lt;/pre&gt;
&lt;pre&gt;                    configuration.Configure();&lt;/pre&gt;
&lt;pre class="alt"&gt;                    configuration.AddAssembly(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Product).Assembly);&lt;/pre&gt;
&lt;pre&gt;                    _sessionFactory = configuration.BuildSessionFactory();&lt;/pre&gt;
&lt;pre class="alt"&gt;                }&lt;/pre&gt;
&lt;pre&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; _sessionFactory;&lt;/pre&gt;
&lt;pre class="alt"&gt;            }&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; ISession OpenSession()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; SessionFactory.OpenSession();&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;pre&gt;    }&lt;/pre&gt;
&lt;pre class="alt"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This class creates a session factory only the first time a client needs a new session.&lt;/p&gt;
&lt;p&gt;Now we can define the Add method in the ProductRepository as follows&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Add(Product product)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ISession session = NHibernateHelper.OpenSession())&lt;/pre&gt;
&lt;pre&gt;                &lt;span class="kwrd"&gt;using&lt;/span&gt; (ITransaction transaction = session.BeginTransaction())&lt;/pre&gt;
&lt;pre class="alt"&gt;                {&lt;/pre&gt;
&lt;pre&gt;                    session.Save(product);&lt;/pre&gt;
&lt;pre class="alt"&gt;                    transaction.Commit();&lt;/pre&gt;
&lt;pre&gt;                }&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;The second run of the test method will again fail with the following message&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_32.png"&gt;&lt;img height="247" width="644" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_15.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;That's because NHibernate is by default configured to use&lt;strong&gt; &lt;a href="http://martinfowler.com/eaaCatalog/lazyLoad.html"&gt;lazy load&lt;/a&gt;&lt;/strong&gt; for all entities. That is the recommended approach and I warmly recommend not to change it for a maximum of flexibility.&lt;/p&gt;
&lt;p&gt;How can we solve this issue? It's easy we have to just make all our properties (and methods) of the domain object(s) virtual. Let's do this for our Product class&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Product&lt;/pre&gt;
&lt;pre&gt;    {&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; Guid Id { get; set; }&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Category { get; set; }&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Discontinued { get; set; }&lt;/pre&gt;
&lt;pre class="alt"&gt;    }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;Now run the test again. It should succeed and we get the following output&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_34.png"&gt;&lt;img height="141" width="644" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_16.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Note the sql spit out by NHibernate.&lt;/p&gt;
&lt;p&gt;Now we think that we have successfully inserted a new product into the database. But let's test it whether it is really so. Let's extend our test method &lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        [Test]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Can_add_new_product()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            var product = &lt;span class="kwrd"&gt;new&lt;/span&gt; Product {Name = &lt;span class="str"&gt;"Apple"&lt;/span&gt;, Category = &lt;span class="str"&gt;"Fruits"&lt;/span&gt;};&lt;/pre&gt;
&lt;pre class="alt"&gt;            IProductRepository repository = &lt;span class="kwrd"&gt;new&lt;/span&gt; ProductRepository();&lt;/pre&gt;
&lt;pre&gt;            repository.Add(product);&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;            &lt;span class="rem"&gt;// use session to try to load the product&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt;(ISession session = _sessionFactory.OpenSession())&lt;/pre&gt;
&lt;pre&gt;            {&lt;/pre&gt;
&lt;pre class="alt"&gt;                var fromDb = session.Get&amp;lt;Product&amp;gt;(product.Id);&lt;/pre&gt;
&lt;pre&gt;                &lt;span class="rem"&gt;// Test that the product was successfully inserted&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="alt"&gt;                Assert.IsNotNull(fromDb);&lt;/pre&gt;
&lt;pre&gt;                Assert.AreNotSame(product, fromDb);&lt;/pre&gt;
&lt;pre class="alt"&gt;                Assert.AreEqual(product.Name, fromDb.Name);&lt;/pre&gt;
&lt;pre&gt;                Assert.AreEqual(product.Category, fromDb.Category);&lt;/pre&gt;
&lt;pre class="alt"&gt;            }&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;Run the test again. Hopefully it will succeed...&lt;/p&gt;
&lt;p&gt;Now we are ready to implement also the other methods of the repository. For testing this we would rather have a repository (that is database table) already containing some products. Nothing easier than this. Just add a method CreateInitialData to the test class as follows&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; Product[] _products = &lt;span class="kwrd"&gt;new&lt;/span&gt;[]&lt;/pre&gt;
&lt;pre&gt;                 {&lt;/pre&gt;
&lt;pre class="alt"&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; Product {Name = &lt;span class="str"&gt;"Melon"&lt;/span&gt;, Category = &lt;span class="str"&gt;"Fruits"&lt;/span&gt;},&lt;/pre&gt;
&lt;pre&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; Product {Name = &lt;span class="str"&gt;"Pear"&lt;/span&gt;, Category = &lt;span class="str"&gt;"Fruits"&lt;/span&gt;},&lt;/pre&gt;
&lt;pre class="alt"&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; Product {Name = &lt;span class="str"&gt;"Milk"&lt;/span&gt;, Category = &lt;span class="str"&gt;"Beverages"&lt;/span&gt;},&lt;/pre&gt;
&lt;pre&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; Product {Name = &lt;span class="str"&gt;"Coca Cola"&lt;/span&gt;, Category = &lt;span class="str"&gt;"Beverages"&lt;/span&gt;},&lt;/pre&gt;
&lt;pre class="alt"&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; Product {Name = &lt;span class="str"&gt;"Pepsi Cola"&lt;/span&gt;, Category = &lt;span class="str"&gt;"Beverages"&lt;/span&gt;},&lt;/pre&gt;
&lt;pre&gt;                 };&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateInitialData()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            &lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt;(ISession session = _sessionFactory.OpenSession())&lt;/pre&gt;
&lt;pre&gt;                &lt;span class="kwrd"&gt;using&lt;/span&gt;(ITransaction transaction = session.BeginTransaction())&lt;/pre&gt;
&lt;pre class="alt"&gt;                {&lt;/pre&gt;
&lt;pre&gt;                    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var product &lt;span class="kwrd"&gt;in&lt;/span&gt; _products)&lt;/pre&gt;
&lt;pre class="alt"&gt;                        session.Save(product);&lt;/pre&gt;
&lt;pre&gt;                    transaction.Commit();&lt;/pre&gt;
&lt;pre class="alt"&gt;                }&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;Call this method from the SetupContext method (after the create schema call) and we are done. Now each time after the database schema is created the database is populated with some products.&lt;/p&gt;
&lt;p&gt;Let's test the Update method of the repository with the following code&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        [Test]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Can_update_existing_product()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            var product = _products[0];&lt;/pre&gt;
&lt;pre class="alt"&gt;            product.Name = &lt;span class="str"&gt;"Yellow Pear"&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;            IProductRepository repository = &lt;span class="kwrd"&gt;new&lt;/span&gt; ProductRepository();&lt;/pre&gt;
&lt;pre class="alt"&gt;            repository.Update(product);&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="rem"&gt;// use session to try to load the product&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ISession session = _sessionFactory.OpenSession())&lt;/pre&gt;
&lt;pre class="alt"&gt;            {&lt;/pre&gt;
&lt;pre&gt;                var fromDb = session.Get&amp;lt;Product&amp;gt;(product.Id);&lt;/pre&gt;
&lt;pre class="alt"&gt;                Assert.AreEqual(product.Name, fromDb.Name);&lt;/pre&gt;
&lt;pre&gt;            }&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;When running for the first time this code will fail since the Update method has not yet been implemented in the repository. &lt;strong&gt;Note&lt;/strong&gt;: This is the expected behavior since in TDD the first time you run a test it should always fail!&lt;/p&gt;
&lt;p&gt;Analogous to the Add method we implement the Update method of the repository. The only difference is that we call the update method of the NHibernate session object instead of the save method.&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Update(Product product)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ISession session = NHibernateHelper.OpenSession())&lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ITransaction transaction = session.BeginTransaction())&lt;/pre&gt;
&lt;pre class="alt"&gt;            {&lt;/pre&gt;
&lt;pre&gt;                session.Update(product);&lt;/pre&gt;
&lt;pre class="alt"&gt;                transaction.Commit();&lt;/pre&gt;
&lt;pre&gt;            }&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Run the test again an watch it succeed.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_38.png"&gt;&lt;img height="130" width="644" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/FirstNHibernatebasedapplication_7586/image_thumb_18.png" alt="image" style="border: 0px none ;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The delete method is straight forward. When testing whether the record has really been deleted we just assert that the value returned by the session's get method is equal to null. Here is the test method&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        [Test]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Can_remove_existing_product()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            var product = _products[0];&lt;/pre&gt;
&lt;pre class="alt"&gt;            IProductRepository repository = &lt;span class="kwrd"&gt;new&lt;/span&gt; ProductRepository();&lt;/pre&gt;
&lt;pre&gt;            repository.Remove(product);&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ISession session = _sessionFactory.OpenSession())&lt;/pre&gt;
&lt;pre class="alt"&gt;            {&lt;/pre&gt;
&lt;pre&gt;                var fromDb = session.Get&amp;lt;Product&amp;gt;(product.Id);&lt;/pre&gt;
&lt;pre class="alt"&gt;                Assert.IsNull(fromDb);&lt;/pre&gt;
&lt;pre&gt;            }&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;and here the implementation of the Remove method in the repository&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Remove(Product product)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ISession session = NHibernateHelper.OpenSession())&lt;/pre&gt;
&lt;pre&gt;                &lt;span class="kwrd"&gt;using&lt;/span&gt; (ITransaction transaction = session.BeginTransaction())&lt;/pre&gt;
&lt;pre class="alt"&gt;                {&lt;/pre&gt;
&lt;pre&gt;                    session.Delete(product);&lt;/pre&gt;
&lt;pre class="alt"&gt;                    transaction.Commit();&lt;/pre&gt;
&lt;pre&gt;                }&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;h4&gt;Querying the Database&lt;/h4&gt;
&lt;p&gt;We still have to implement the three methods which query the database for objects. Let's start with the most easy one, the GetById. First we write the test &lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        [Test]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Can_get_existing_product_by_id()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            IProductRepository repository = &lt;span class="kwrd"&gt;new&lt;/span&gt; ProductRepository();&lt;/pre&gt;
&lt;pre class="alt"&gt;            var fromDb = repository.GetById(_products[1].Id);&lt;/pre&gt;
&lt;pre&gt;            Assert.IsNotNull(fromDb);&lt;/pre&gt;
&lt;pre class="alt"&gt;            Assert.AreNotSame(_products[1], fromDb);&lt;/pre&gt;
&lt;pre&gt;            Assert.AreEqual(_products[1].Name, fromDb.Name);&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;and then the code to fulfill the test&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Product GetById(Guid productId)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ISession session = NHibernateHelper.OpenSession())&lt;/pre&gt;
&lt;pre&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; session.Get&amp;lt;Product&amp;gt;(productId);&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now that was easy. For the following two methods we use a new method of the session object. Let's start with the GetByName method. As usual we write the test first&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        [Test]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Can_get_existing_product_by_name()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            IProductRepository repository = &lt;span class="kwrd"&gt;new&lt;/span&gt; ProductRepository();&lt;/pre&gt;
&lt;pre class="alt"&gt;            var fromDb = repository.GetByName(_products[1].Name);&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;            Assert.IsNotNull(fromDb);&lt;/pre&gt;
&lt;pre&gt;            Assert.AreNotSame(_products[1], fromDb);&lt;/pre&gt;
&lt;pre class="alt"&gt;            Assert.AreEqual(_products[1].Id, fromDb.Id);&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;The implementation of the GetByName method can be done by using two different approaches. The first is using HQL (Hibernate Query Language) and the second one HCQ (Hibernate Criteria Query). Let's start with HQL. HQL is a object oriented query language similar (but not equal to) SQL.&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Product GetByName(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ISession session = NHibernateHelper.OpenSession())&lt;/pre&gt;
&lt;pre&gt;            {&lt;/pre&gt;
&lt;pre class="alt"&gt;                Product product = session&lt;/pre&gt;
&lt;pre&gt;                    .CreateQuery(&lt;span class="str"&gt;"from Product p where p.Name=:name"&lt;/span&gt;)&lt;/pre&gt;
&lt;pre class="alt"&gt;                    .SetString(&lt;span class="str"&gt;"name"&lt;/span&gt;, name)&lt;/pre&gt;
&lt;pre&gt;                    .UniqueResult&amp;lt;Product&amp;gt;();&lt;/pre&gt;
&lt;pre class="alt"&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; product;&lt;/pre&gt;
&lt;pre&gt;            }&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In the above sample I have introduced a commonly used technique when using NHibernate. It's called &lt;a href="http://en.wikipedia.org/wiki/Fluent_interface"&gt;fluent interfaces&lt;/a&gt;. As a result the code is less verbose and easier to understand. You can see that a HQL query is a string which can have embedded (named) parameters. Parameters are prefixed by a ':'. NHibernate defines many helper methods (like SetString used in the example) to assign values of various types to those parameters. Finally by using UniqueResult I tell NHibernate that I expect only one record to return. If more than one record is returned by the HQL query then an exception is raised. To get more information about HQL please read the &lt;a href="http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/queryhql.html"&gt;online documentation&lt;/a&gt;.&lt;/p&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;The second version uses a criteria query to search the requested product.&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Product GetByName(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ISession session = NHibernateHelper.OpenSession())&lt;/pre&gt;
&lt;pre&gt;            {&lt;/pre&gt;
&lt;pre class="alt"&gt;                Product product = session&lt;/pre&gt;
&lt;pre&gt;                    .CreateCriteria(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Product))&lt;/pre&gt;
&lt;pre class="alt"&gt;                    .Add(Restrictions.Eq(&lt;span class="str"&gt;"Name"&lt;/span&gt;, name))&lt;/pre&gt;
&lt;pre&gt;                    .UniqueResult&amp;lt;Product&amp;gt;();&lt;/pre&gt;
&lt;pre class="alt"&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; product;&lt;/pre&gt;
&lt;pre&gt;            }&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;Many users of NHibernate think that this approach is more object oriented. On the other hand a complex query written with criteria syntax can quickly become difficult to understand.&lt;/p&gt;
&lt;p&gt;The last method to implement is GetByCategory. This method returns a list of products. The test can be implemented as follows&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        [Test]&lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Can_get_existing_products_by_category()&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            IProductRepository repository = &lt;span class="kwrd"&gt;new&lt;/span&gt; ProductRepository();&lt;/pre&gt;
&lt;pre class="alt"&gt;            var fromDb = repository.GetByCategory(&lt;span class="str"&gt;"Fruits"&lt;/span&gt;);&lt;/pre&gt;
&lt;pre&gt; &lt;/pre&gt;
&lt;pre class="alt"&gt;            Assert.AreEqual(2, fromDb.Count);&lt;/pre&gt;
&lt;pre&gt;            Assert.IsTrue(IsInCollection(_products[0], fromDb));&lt;/pre&gt;
&lt;pre class="alt"&gt;            Assert.IsTrue(IsInCollection(_products[1], fromDb));&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;pre class="alt"&gt; &lt;/pre&gt;
&lt;pre&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsInCollection(Product product, ICollection&amp;lt;Product&amp;gt; fromDb)&lt;/pre&gt;
&lt;pre class="alt"&gt;        {&lt;/pre&gt;
&lt;pre&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var item &lt;span class="kwrd"&gt;in&lt;/span&gt; fromDb)&lt;/pre&gt;
&lt;pre class="alt"&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (product.Id == item.Id)&lt;/pre&gt;
&lt;pre&gt;                    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;and the method itself might contain the following code&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; ICollection&amp;lt;Product&amp;gt; GetByCategory(&lt;span class="kwrd"&gt;string&lt;/span&gt; category)&lt;/pre&gt;
&lt;pre&gt;        {&lt;/pre&gt;
&lt;pre class="alt"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ISession session = NHibernateHelper.OpenSession())&lt;/pre&gt;
&lt;pre&gt;            {&lt;/pre&gt;
&lt;pre class="alt"&gt;                var products = session&lt;/pre&gt;
&lt;pre&gt;                    .CreateCriteria(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Product))&lt;/pre&gt;
&lt;pre class="alt"&gt;                    .Add(Restrictions.Eq(&lt;span class="str"&gt;"Category"&lt;/span&gt;, category))&lt;/pre&gt;
&lt;pre&gt;                    .List&amp;lt;Product&amp;gt;();&lt;/pre&gt;
&lt;pre class="alt"&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; products;&lt;/pre&gt;
&lt;pre&gt;            }&lt;/pre&gt;
&lt;pre class="alt"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;h3&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;Summary&lt;/h3&gt;
&lt;p&gt;In this article I have shown you how to implement a basic sample domain, define the mapping to a database and how to configure NHibernate to be able to persist domain objects in the database. I have shown you how to typically write and test CRUD methods for your domain objects. I have taken MS SQL Compact Edition as sample database but any other supported database can be used (you only have to change the hibernate.cfg.xml file accordingly). Ee have no dependencies on external frameworks or tools other than the database and NHibernate itself (.NET of course never counts here).&lt;/p&gt;&lt;img src="http://blogs.hibernatingrhinos.com/nhibernate/aggbug/5.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>NHibernate's Answers</dc:creator>
            <guid>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx</guid>
            <pubDate>Tue, 01 Apr 2008 12:29:46 GMT</pubDate>
            <wfw:comment>http://blogs.hibernatingrhinos.com/nhibernate/comments/5.aspx</wfw:comment>
            <comments>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx#feedback</comments>
            <slash:comments>274</slash:comments>
            <wfw:commentRss>http://blogs.hibernatingrhinos.com/nhibernate/comments/commentRss/5.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Prepare your system for NHibernate</title>
            <link>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/03/31/prepare-your-system-for-nhibernate.aspx</link>
            <description>&lt;p&gt;In this post (and a subsequent one) I'll introduce two ways how to prepare a developer machine to use &lt;strong&gt;NHibernate&lt;/strong&gt; as a ORM (Object Relational Modeling) tool.&lt;/p&gt;
&lt;p&gt;The first approach describes the &lt;strong&gt;minimal&lt;/strong&gt; setup needed to use NHibernate when developing an application. The second approach on the other hand describes an infrastructure which is not only based on NHibernate but also on another very useful framework called &lt;strong&gt;Rhino Tools&lt;/strong&gt;. This framework simplifies the usage of NHibernate very much but is by no means required. I personally have successfully developed medium sized and large customer projects based on latter kind of setup.&lt;/p&gt;
&lt;p&gt;In this article the focus is on &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development"&gt;TDD&lt;/a&gt; (Test Driven Development) and we want to approach the topic by adhering to &lt;a href="http://de.wikipedia.org/wiki/Domain-Driven_Design"&gt;DDD&lt;/a&gt; (Domain Driven Design). Although NHibernate can also be used to generate the domain model by starting from an existing database schema I'll concentrate on the opposite direction and start with a domain model first and let NHibernate generate the database schema from the model (and the mapping meta data).&lt;/p&gt;
&lt;h2&gt;How to start&lt;/h2&gt;
&lt;p&gt;First you have to download NHibernate. Since NHibernate is an open source project anybody has free access to the (most current) binaries and/or source code. The source code is stored in a SVN repository (&lt;a href="http://subversion.tigris.org/"&gt;Subversion&lt;/a&gt; Source Control System) and can be found &lt;a href="https://nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/"&gt;here&lt;/a&gt;. The most current source code is called the "trunk". &lt;/p&gt;
&lt;h3&gt;The Operating System&lt;/h3&gt;
&lt;p&gt;I expect you are working on a machine with one of the following operating systems&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Windows XP SP2, &lt;/li&gt;
    &lt;li&gt;Windows VISTA, &lt;/li&gt;
    &lt;li&gt;Windows Server 2003 or &lt;/li&gt;
    &lt;li&gt;Windows Server 2008. &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Which version of Visual Studio&lt;/h3&gt;
&lt;p&gt;We use the brand new &lt;strong&gt;NHibernate 2.0 Alpha 1&lt;/strong&gt; version. This version of NHibernate can work either with .NET 2.0 or .NET 3.5. For the former version you should have at least Visual Studio 2005 Professional installed and for the latter you need at least VS 2008 Professional. Of course you can also work with the Express Edition but they have some serious limitations (e.g. you cannot use any Add-In with VS). Now if you have some money left I strongly recommend you install the &lt;a href="http://www.jetbrains.com/resharper/"&gt;ReSharper&lt;/a&gt; Add-In as your productivity tool. I promise you it'll boost your productivity by factors! This investment is worth every penny (When using VS 2008 try to also use the EAP release of ReSharper 4.0 which you can find &lt;a href="http://www.jetbrains.net/confluence/display/ReSharper/ReSharper+4.0+Nightly+Builds"&gt;here&lt;/a&gt;. At the time being release 755 seems to be rather stable!).&lt;/p&gt;
&lt;h2&gt;Download the NHibernate binaries&lt;/h2&gt;
&lt;p&gt;You can grab the latest NHibernate binaries &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=73818"&gt;here&lt;/a&gt;. At the time being this is the Alpha 1 release of the version2.0.0. Download the file "&lt;strong&gt;NHibernate-2.0.0.Alpha1-bin.zip&lt;/strong&gt;". Extract the zip files to a folder where you will place all your Open Source Software (OSS). That is create a new folder, e.g. "&lt;strong&gt;m:\dev\OSS\NHibernate&lt;/strong&gt;" and extract the binaries to this folder. The binaries are compiled against .NET 2.0. If you prefer to have binaries compiled agains .NET 3.5 you have to build NHibernate from the trunk as described in the next chapter. Otherwise you can skip the following chapter and move directly to the chapter "&lt;strong&gt;Prepare for TDD&lt;/strong&gt;".&lt;/p&gt;
&lt;h2&gt;Build NHibernate from the Trunk&lt;/h2&gt;
&lt;p&gt;To download the source code you need a SVN client application installed on your developer machine. There exist various open source as well as commercial clients. One of the most known (open source) clients is &lt;strong&gt;TortoiseSVN&lt;/strong&gt; and can be found &lt;a href="http://tortoisesvn.tigris.org/"&gt;here&lt;/a&gt;. &lt;strong&gt;TortoiseSVN&lt;/strong&gt; integrates very nicely with Windows Explorer. Download and install it on your machine. Restart your machine after the installation.&lt;/p&gt;
&lt;h4&gt;Download the NHibernate Source Code&lt;/h4&gt;
&lt;p&gt;Create a (sub-)directory OSS (Open Source Software; e.g. m:\dev\OSS). Create a subdirectory NHibernate within the OSS directory.&lt;/p&gt;
&lt;p&gt;Right click on the NHibernate directory and choose the context menu "&lt;strong&gt;SVN checkout...". &lt;/strong&gt;In the dialog box enter the url to the trunk as shown below. Double check the checkout directory and then press OK.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_2.png"&gt;&lt;img height="328" width="470" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_thumb.png" alt="TortoiseSVN download dialog" style="border-width: 0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The SVN client will immediately start to download the NHibernate source code as well as the documentation. Depending on the speed of your Internet connection this may take some time to finish. You should see some thing like this&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_4.png"&gt;&lt;img height="363" width="566" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_thumb_1.png" alt="TortoiseSVN download progress dialog" style="border-width: 0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;When the download is completed we can now compile NHibernate (remember: we have downloaded the source code and not the binaries!). Don't fear, this is an automated process. But wait, for this to work we need &lt;strong&gt;NAnt&lt;/strong&gt;, another open source tool. &lt;/p&gt;
&lt;h3&gt;Download and install NAnt&lt;/h3&gt;
&lt;p&gt;You can get the latest release of NAnt &lt;a href="http://nant.sourceforge.net/"&gt;here&lt;/a&gt;. This time we download the binaries (and not the source code) since it is "only" a helper tool for now. At the time of this writing I recommend downloading the &lt;strong&gt;0.86 Beta 1&lt;/strong&gt; release since this release is the first one that can compile .NET 3.5 projects.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_6.png"&gt;&lt;img height="381" width="287" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_thumb_2.png" alt="NAnt" style="border-width: 0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Download and extract the NAnt binaries (nant-0.86-beta1-bin.zip) into a directory on your developer machine (e.g. m:\dev\OSS\NAnt).&lt;/p&gt;
&lt;h3&gt;Compile NHibernate&lt;/h3&gt;
&lt;p&gt;Now it's definitively time to compile NHibernate. Open a console and go to the root directory of the NHibernate source (e.g. m:\dev\OSS\NHibernate\nhibernate). There you should find amongst others a file called &lt;strong&gt;default.build&lt;/strong&gt;. This file contains the instructions for NAnt how to compile NHibernate. You can either compile NHibernate for .NET 3.5 (it's the default) or for .NET 2.0. In the console enter the following commands for the 2 scenarios (assuming you have NAnt installed in the same OSS folder as NHibernate)&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;For .Net 3.5 (default)      &lt;br /&gt;
    ..\..\nant\bin\nant.exe &lt;/li&gt;
    &lt;li&gt;For .NET 2.0      &lt;br /&gt;
    ..\..\nant\bin\nant.exe "-t:net-2.0" &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The source code should now be compiled and after some time you should see some thing like this&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_8.png"&gt;&lt;img height="644" width="681" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_thumb_3.png" alt="image" style="border-width: 0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;It's important that the second last line states "BUILD SUCCEEDED".&lt;/p&gt;
&lt;p&gt;After compiling the source code you should find a new sub-folder "build" in your NHibernate folder which contains all the binaries. Depending on the chosen scenario you will find the binaries in either a sub-folder "&lt;strong&gt;net-3.5&lt;/strong&gt;" or "&lt;strong&gt;net-2.0"&lt;/strong&gt;. Didn't I tell you that it's easy...!&lt;/p&gt;
&lt;h2&gt;Prepare for TDD&lt;/h2&gt;
&lt;p&gt;Are we ready now? Nope! Since we're proud fellows of the &lt;a href="http://altnetpedia.com"&gt;ALT.NET&lt;/a&gt; way we don't want just start coding. No, we do &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development"&gt;TDD&lt;/a&gt;. Doing so we need a test framework. There exist several well known frameworks (e.g. &lt;a href="http://www.nunit.org/index.php"&gt;NUnit&lt;/a&gt;, &lt;a href="http://www.mbunit.com/"&gt;MbUnit&lt;/a&gt;, &lt;a href="http://www.codeplex.com/xunit"&gt;XUnit&lt;/a&gt;, etc.). In our examples we either use NUnit or MbUnit. Let's start with NUnit since NHibernate uses it too for its own test (you can download it from &lt;a href="http://www.nunit.org/index.php"&gt;here&lt;/a&gt;). Note: we don't have to download it, since we can use the binaries provided with NHibernate (the only files we actually need are &lt;strong&gt;nunit.framework.dll&lt;/strong&gt; and &lt;strong&gt;nuni.core.dll&lt;/strong&gt;).&lt;/p&gt;
&lt;h3&gt;Team development and Continuous Integration&lt;/h3&gt;
&lt;p&gt;Although this article doesn't explain these two topics you still should be prepared to develop in a team and to use &lt;a href="http://martinfowler.com/articles/continuousIntegration.html"&gt;continuous integration&lt;/a&gt;. Why do I mention this? Well, we should do some further configuration of our environment to be prepared for this situations. Since it's easy to do - why not do it NOW...&lt;/p&gt;
&lt;p&gt;A solution at best should have &lt;strong&gt;no&lt;/strong&gt; external dependencies (ok, .NET we don't count here). If it has, then these dependencies should become a part of the solution (setup). What does this mean for us? Well our projects will have external dependencies, NHibernate is one of them. Another one is NUnit and still another one the database we'll use. A possible solution for this scenario is to &lt;strong&gt;not&lt;/strong&gt; rely on assemblies registered in the GAC or any other "common" or "programs" folders of the system. Instead create a directory called e.g. SharedLibs which will be part of your solution and copy all external assemblies into this folder. The solution then only references external assemblies from this folder (an exception are all the .NET assemblies). If you use a source control system (and you should!) then put this folder under version control too!&lt;/p&gt;
&lt;h3&gt;Our first project&lt;/h3&gt;
&lt;p&gt;Create a folder FirstSample (e.g. m:\dev\projects\FirstSolution). Create a sub-folder SharedLibs. Copy the following assemblies into this folder (from the NHibernate bin folder which was created during compilation of NHibernate)&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;nunit.framework.dll &lt;/li&gt;
    &lt;li&gt;nuni.core.dll &lt;/li&gt;
    &lt;li&gt;nhibernate.dll &lt;/li&gt;
    &lt;li&gt;iesi.collections.dll &lt;/li&gt;
    &lt;li&gt;Castle.DynamicProxy2.dll &lt;/li&gt;
    &lt;li&gt;Castle.Core.dll &lt;/li&gt;
    &lt;li&gt;log4net.dll &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Create a sub-folder src (e.g. m:\dev\projects\FirstSolution\src).&lt;/p&gt;
&lt;p&gt;Run VS 2008 and create a new solution. Choose C# Class Library as Template and call it &lt;strong&gt;FirstSolution&lt;/strong&gt;. Choose "m:\dev\projects\FirstSolution\src" as location and uncheck "Create directory for solution". Click OK now.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_10.png"&gt;&lt;img height="574" width="808" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_thumb_4.png" alt="image" style="border-width: 0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Immediately add an additional class library project to the solution and call it FirstSolution.Tests. This project will contain all our test classes (remember we're doing TDD). You should then have a structure similar to this one:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_12.png"&gt;&lt;img height="261" width="296" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/image_thumb_5.png" alt="image" style="border-width: 0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;In this article I have shown how to prepare a developer machine for using the very latest version of NHibernate as an ORM tool in an application that is developed by using TDD and DDD. First we installed the prerequisites then we either downloaded the NHibernate binaries or we download and compiled the source code of NHibernate and finally we prepared a first .NET solution to start with.&lt;/p&gt;
&lt;p&gt;In the &lt;a href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx"&gt;next article&lt;/a&gt; I'll discuss how implement this very first NHibernate based solution.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/Blog%20Signature%20Gabriel_2.png"&gt;&lt;img height="17" width="240" border="0" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/nhibernate/WindowsLiveWriter/PrepareyoursystemforNHibernate_12F89/Blog%20Signature%20Gabriel_thumb.png" alt="Blog Signature Gabriel" style="border: 0px none ;" /&gt;&lt;/a&gt;   &lt;/p&gt;
&lt;p&gt;.&lt;/p&gt;&lt;img src="http://blogs.hibernatingrhinos.com/nhibernate/aggbug/4.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>NHibernate's Answers</dc:creator>
            <guid>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/03/31/prepare-your-system-for-nhibernate.aspx</guid>
            <pubDate>Mon, 31 Mar 2008 21:08:25 GMT</pubDate>
            <wfw:comment>http://blogs.hibernatingrhinos.com/nhibernate/comments/4.aspx</wfw:comment>
            <comments>http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/03/31/prepare-your-system-for-nhibernate.aspx#feedback</comments>
            <slash:comments>218</slash:comments>
            <wfw:commentRss>http://blogs.hibernatingrhinos.com/nhibernate/comments/commentRss/4.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>