<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>mhinze.com &#187; codecampserver</title>
	<atom:link href="http://mhinze.com/tag/codecampserver/feed/" rel="self" type="application/rss+xml" />
	<link>http://mhinze.com</link>
	<description>Matt Hinze, learning in public</description>
	<lastBuildDate>Tue, 14 Feb 2012 16:31:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mhinze.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>mhinze.com &#187; codecampserver</title>
		<link>http://mhinze.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mhinze.com/osd.xml" title="mhinze.com" />
	<atom:link rel='hub' href='http://mhinze.com/?pushpress=hub'/>
		<item>
		<title>Linq to NHibernate in 10 minutes</title>
		<link>http://mhinze.com/2008/07/22/linq-to-nhibernate-in-10-minutes/</link>
		<comments>http://mhinze.com/2008/07/22/linq-to-nhibernate-in-10-minutes/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 12:45:59 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[codecampserver]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[nhibernate]]></category>

		<guid isPermaLink="false">http://mhinze.com/?p=52</guid>
		<description><![CDATA[If you are curious about Linq to NHibernate and want to quickly check it out, here is an easy way to do it. Check out a copy of the CodeCampServer source (svn).&#160; CodeCampServer is easy to work with because it &#8230; <a href="http://mhinze.com/2008/07/22/linq-to-nhibernate-in-10-minutes/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhinze.com&amp;blog=678824&amp;post=52&amp;subd=mhinze&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you are curious about <a href="http://www.ayende.com/Blog/archive/2007/03/17/Implementing-Linq-for-NHibernate-A-How-To-Guide--Part.aspx">Linq to NHibernate</a> and want to quickly check it out, here is an easy way to do it.</p>
<p>Check out a copy of the <a href="http://codecampserver.org">CodeCampServer</a> source (<a href="http://codecampserver.googlecode.com/svn/trunk/">svn</a>).&nbsp; CodeCampServer is easy to work with because it has good tests on an already-working NHibernate implementation.</p>
<p>Check out a copy of <a href="http://sourceforge.net/projects/nhcontrib/">NH Contrib</a> (<a href="https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/">svn</a>), open the NHibernate.Linq solution in Visual Studio and build. You may have to remove the compiler flag that indicates .NET 3.5 sp1 is available.</p>
<p>Open the CodeCampServer.sln and remove the NHibernate.dll reference from the DataAccess and IntegrationTests projects.&nbsp; Add a reference to NHibernate.dll from the NHibernate.Linq bin directory.&nbsp; Build and run tests.&nbsp; I had to play with the <a href="http://codecampserver.googlecode.com/svn/trunk/src/IntegrationTests/DataAccess/DatabaseTesterBase.cs">DatabaseTesterBase.recreateDatabase()</a> method because I think are are still some bugs in Export():</p>
<pre class="code"><span style="color:blue;">public static void </span>recreateDatabase()
{
    <span style="color:blue;">var </span>exporter = <span style="color:blue;">new </span><span style="color:#2b91af;">SchemaExport</span>(<span style="color:blue;">new </span><span style="color:#2b91af;">HybridSessionBuilder</span>().GetConfiguration());
    exporter.Drop(<span style="color:blue;">false</span>, <span style="color:blue;">true</span>);
    exporter.Create(<span style="color:blue;">false</span>, <span style="color:blue;">true</span>);
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Now add a reference to NHibernate.Linq.dll in the DataAccess project. You can start <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx">writing queries</a> and check your work with the integration tests that already exist. Here are a few simple queries for <a href="http://codecampserver.googlecode.com/svn/trunk/src/DataAccess/Impl/ConferenceRepository.cs">ConferenceRepository</a>:</p>
<p><a href="http://11011.net/software/vspaste"></a>
<pre class="code"><span style="color:blue;">public </span><span style="color:#2b91af;">Conference</span>[] GetAllConferences()
{
    <span style="color:#2b91af;">ISession </span>session = getSession();
    <span style="color:blue;">var </span>query = <span style="color:blue;">from </span>conference <span style="color:blue;">in </span>session.Linq&lt;<span style="color:#2b91af;">Conference</span>&gt;() <span style="color:blue;">select </span>conference;
    <span style="color:blue;">return </span>query.ToList().ToArray();
}

<span style="color:blue;">public </span><span style="color:#2b91af;">Conference </span>GetConferenceByKey(<span style="color:blue;">string </span>key)
{
    <span style="color:#2b91af;">ISession </span>session = getSession();
    <span style="color:blue;">var </span>query = <span style="color:blue;">from </span>conference <span style="color:blue;">in </span>session.Linq&lt;<span style="color:#2b91af;">Conference</span>&gt;()
                <span style="color:blue;">where </span>conference.Key == key
                <span style="color:blue;">select </span>conference;
    <span style="color:blue;">return </span>query.Distinct().Single();
}

<span style="color:blue;">public </span><span style="color:#2b91af;">Conference </span>GetFirstConferenceAfterDate(<span style="color:#2b91af;">DateTime </span>date)
{
    <span style="color:#2b91af;">ISession </span>session = getSession();
    <span style="color:blue;">var </span>query = <span style="color:blue;">from </span>conference <span style="color:blue;">in </span>session.Linq&lt;<span style="color:#2b91af;">Conference</span>&gt;()
                <span style="color:blue;">where </span>conference.StartDate &gt;= date
                <span style="color:blue;">orderby </span>conference.StartDate
                <span style="color:blue;">select </span>conference;
    <span style="color:blue;">return </span>query.First();
}

<span style="color:blue;">public </span><span style="color:#2b91af;">Conference </span>GetMostRecentConference(<span style="color:#2b91af;">DateTime </span>date)
{
    <span style="color:#2b91af;">ISession </span>session = getSession();
    <span style="color:blue;">var </span>query = <span style="color:blue;">from </span>conference <span style="color:blue;">in </span>session.Linq&lt;<span style="color:#2b91af;">Conference</span>&gt;()
            <span style="color:blue;">where </span>conference.EndDate &lt;= date
            <span style="color:blue;">select </span>conference;
    query.OrderByDescending(conference =&gt; conference.EndDate);
    <span style="color:blue;">return </span>query.First();
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/mhinze.wordpress.com/52/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/mhinze.wordpress.com/52/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mhinze.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mhinze.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mhinze.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mhinze.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mhinze.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mhinze.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mhinze.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mhinze.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mhinze.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mhinze.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mhinze.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mhinze.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mhinze.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mhinze.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhinze.com&amp;blog=678824&amp;post=52&amp;subd=mhinze&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mhinze.com/2008/07/22/linq-to-nhibernate-in-10-minutes/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d6043840ea98542a9c9331c7e7940b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mhinze</media:title>
		</media:content>
	</item>
	</channel>
</rss>
