<?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/"
	>

<channel>
	<title>Web Dev Bros &#187; SQL</title>
	<atom:link href="http://www.webdevbros.net/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevbros.net</link>
	<description>hot talk about web development</description>
	<lastBuildDate>Thu, 20 Jan 2011 19:55:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Nhibernate returns duplicate results on paged data sets &#8211; work around</title>
		<link>http://www.webdevbros.net/2010/11/11/nhibernate-returns-duplicate-results-on-paged-data-sets-work-around/</link>
		<comments>http://www.webdevbros.net/2010/11/11/nhibernate-returns-duplicate-results-on-paged-data-sets-work-around/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 12:02:13 +0000</pubDate>
		<dc:creator>Dai Bok</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[nhibernate]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/?p=909</guid>
		<description><![CDATA[There is a problem with Nhibernate, when paging record sets, using SQLServer 2008. This offers a work around, to fix this problem.]]></description>
			<content:encoded><![CDATA[<p>Recently, while implementing a page-able data grid with <a href="http://nhforge.org/">nHibernate </a>and  <a href="http://mvccontrib.codeplex.com/">MVC Contrib Grid</a>, I came across a strange problem. My result set had duplicates, and the strange thing was that it would only happen when paging my record set. Anyway, I thought I would write a little post about how I solved the problem, just in case someone else comes across it. </p>
<p>Firstly, lets look at simplified description of the problem. Those using MySQL have the luxury of limit, which makes paging data sets a breeze, but in SQL Server(and Oracle) things get a bit more “tricky”. The trick is to count the rows on the result set, using RowCount over something, and mix that in with a sub query, but there is a problem with nHibernate T-SQL 2005 Dialect. The RowCount was being used on the sub-query, and not the parent query. Now that I had discovered the problem.</p>
<blockquote><p><strong> &#8220;ROW_NUMBER() OVER(ORDER BY CURRENT_TIMESTAMP) as __hibernate_sort_row&#8221;</strong> is in the wrong place!</p></blockquote>
<p>After some research, I found that other people were having this problem too.<a href="http://www.daczkowski.net/2010/09/07/rows-duplication-for-certain-nhibernate-queries-%E2%80%93-workaround/"> Marcin Daczkowski has an excellent work-around, that he blogged about</a>, he also describes the problem with some NH generated SQL examples, I won’t repeat myself here, so have a look at his post if you are not sure and check his <a href="http://216.121.112.228/browse/NH-2214">bug report here</a>. </p>
<p><a href="http://julianjelfs.wordpress.com/2009/04/03/nhibernate-removing-duplicates-combined-with-paging/">I found a another solution here too- not sure this one works though</a>, ultimately I had to come up with a solution that suited my project.</p>
<p>There are some reasons why I can’t use Marcin Daczkowski solution.<br />
<br />
<strong> &#8211; Firstly</strong>, it does not look like the guys at nHibernate be able to release the patched version of nHibernate any time soon,I guess they are very busy working hard on version 3.0! Can&#8217;t wait for that realease!  <a href="http://216.121.112.228/browse/NH-2214?focusedCommentId=20075&amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_20075">see the comments here.</a><br />
<br />
<strong> &#8211; Secondly</strong>, if I build my own version of nHibernate, I will need to also rebuild all my dependencies, linking them with Marcins patched version. That means <strong>FluentNHibernate</strong> needs to be rebuilt, <strong>NHibernate.Caches.SysCache</strong> needs to be rebuilt, <strong>NHibernate.ByteCode.Castle</strong> needs to be rebuilt, you get the picture?</p>
<p>So after some thought and source code investigation, I came up with the idea of making a customised Dialect, and just use Darcins patched files. Now, I don’t need to build a patched version of my all my open source dependencies, as I have my own SQL dialect set up in the fluent configuration.</p>
<p><code><br />
        _sessionFactory = Fluently.<span style="color:#3399CC">Configure</span>()<br />
 &nbsp; &nbsp;  &nbsp; .Database(<span style="color:#3399CC">MsSqlConfiguration</span><br />
 &nbsp; &nbsp;  &nbsp; .MsSql2008<br />
 &nbsp; &nbsp;  &nbsp; .ConnectionString(connectionString)<br />
 &nbsp; &nbsp;  &nbsp; .CurrentSessionContext(<span style="color:#CC3300">"web"</span>)<br />
 &nbsp; &nbsp;  &nbsp; .Dialect(<span style="color:#3333CC">CustomSQL2008Dialect</span>)<br />
                )<br />
</code></p>
<p> My Dialect classes are set up like this:</p>
<p><code><br />
<span style="color:#3333CC"> public class </span> <span style="color:#3399CC"> CustomSQL2008Dialect: CustomSQL2005Dialect </span> {<br />
 &nbsp; &nbsp;  &nbsp; <span style="color:#3333CC">public </span> <span style="color:#3399CC">  GWMsSql2008Dialect</span> () {<br />
 &nbsp; &nbsp;  &nbsp;  &nbsp; &nbsp;  &nbsp;  <span style="color:#347C17"> // Duplicate of the contents of MsSsql2008Dialect constructor  goes here </span><br />
&nbsp; &nbsp;  &nbsp;   }<br />
 }</p>
<p><span style="color:#3333CC"> public class </span> <span style="color:#3399CC"> CustomSQL2005Dialect: MsSql2000Dialect </span> {<br />
 &nbsp; &nbsp;  &nbsp; <span style="color:#347C17"> // the contents Darcins MsSql2005Dialect file goes here.<br />
 &nbsp; &nbsp;  &nbsp; // <a href="http://216.121.112.228/browse/NH-2214"> MsSql2005Dialect at NHibernate JIRA</a></span><br />
 }<br />
</code></p>
<p>Luckily, I have unit tests set up for all my repository methods, and after seeing the green bar in NUnit, I was more than satisfied with the custom dialect. I hope the guys at NHibernate manage to get things working in their next release, keep up the good work guys! And a special thanks to<br />
to Darcin, for writing the patch. </p>
<p>
Here is a copy <a href='http://www.webdevbros.net/wp-content/uploads/2011/01/CustomSql2008Dialect.cs_.zip'>the Custom Sql 2008 Dialect</a>. </p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2010/11/11/nhibernate-returns-duplicate-results-on-paged-data-sets-work-around/&amp;t=Nhibernate+returns+duplicate+results+on+paged+data+sets+-+work+around&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2010/11/11/nhibernate-returns-duplicate-results-on-paged-data-sets-work-around/&amp;title=Nhibernate+returns+duplicate+results+on+paged+data+sets+-+work+around&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2010/11/11/nhibernate-returns-duplicate-results-on-paged-data-sets-work-around/&amp;title=Nhibernate+returns+duplicate+results+on+paged+data+sets+-+work+around&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Nhibernate+returns+duplicate+results+on+paged+data+sets+-+work+around;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2010/11/11/nhibernate-returns-duplicate-results-on-paged-data-sets-work-around/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2010/11/11/nhibernate-returns-duplicate-results-on-paged-data-sets-work-around/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>FluentNhibernate and Stored Procedures</title>
		<link>http://www.webdevbros.net/2009/11/25/fluentnhibernate-and-stored-procedures/</link>
		<comments>http://www.webdevbros.net/2009/11/25/fluentnhibernate-and-stored-procedures/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 10:59:27 +0000</pubDate>
		<dc:creator>Dai Bok</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[general stuff]]></category>
		<category><![CDATA[nhibernate]]></category>
		<category><![CDATA[Fluent NHibernate]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/?p=808</guid>
		<description><![CDATA[I am evaluating FluentNHibernate (FNH), to see if it is suitable for a project I am working on. Disappointingly, FNH does not support Store procedures of the box. Of course, FNH is under the BSD licence, so I am sure those who are confident enough can implement this for the rest of us! This post [...]]]></description>
			<content:encoded><![CDATA[<p>I am evaluating <a href="http://fluentnhibernate.org/">FluentNHibernate </a> (FNH), to see if it is suitable for a project I am working on. Disappointingly, FNH does not support Store procedures of the box. Of course, FNH is under the BSD licence, so I am sure those who are confident enough can implement this for the rest of us! This post will show how I got FNH to work with stored procedures, and can hopefully be followed as a working example.</p>
<p>FNH extends NHibernate, and automagically generates XML mapping files for your objects. Unfortunately, to get stored procedures to work, you need to take a step backwards, and create good old fashioned hbm.xml files, doing the mappings manually.</p>
<p>Firstly , let us look at the results  of the stored procedure that we want to map.</p>
<table border="0" align="center">
<tbody>
<tr>
<td>ID</td>
<td>enDescription</td>
<td>cyDescription</td>
<td>IsActive</td>
</tr>
<tr>
<td>1</td>
<td>Swansea</td>
<td>Abertawe</td>
<td>True</td>
</tr>
<tr>
<td>2</td>
<td>Cardiff</td>
<td>Caerdydd</td>
<td>True</td>
</tr>
<tr>
<td>3</td>
<td>Newport</td>
<td>Cas Newydd</td>
<td>False</td>
</tr>
</tbody>
</table>
<p>The class that will use this data is called lookup.</p>
<p>The code for this class is:</p>
<div style="font-family: Courier New;font-size: 10pt;color: black;background: white">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;<span style="color: blue">namespace</span> Entities {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">Lookup</span>&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">int</span> Id { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">string</span> EnDescription { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;5</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">string</span> CyDescription { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;6</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">bool</span> IsActive { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;7</span>&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;8</span>&nbsp;}</p>
</div>
<p>&nbsp; <br />
This object will be used to populate a simple drop down list, so that a user can select their county.</p>
<p>When I started using FluentHNibernate, I wanted to totally avoid using XML mappings, so I skipped<a href="http://www.amazon.co.uk/gp/product/193239415X?ie=UTF8&amp;tag=daisramblin-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=193239415X"> chapters 3 and 6 of Hibernate in Action.</a><img class=" luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs luqmsfcfqseksqyogrfs pcshjncfdcdawbvrvmch pcshjncfdcdawbvrvmch" style="border:none !important;margin:0px !important" src="http://www.assoc-amazon.co.uk/e/ir?t=daisramblin-21&amp;l=as2&amp;o=2&amp;a=193239415X" border="0" alt="" width="1" height="1" /> My first mistake! So for those attempting this, it may be worth your while understanding Hibernate mappings before you proceed. (You may also ask why I have the Java Book and my code is in C#, that is because I am quite used to working in different programming languages, so those who prefer examples in .Net examples check <a href="http://www.amazon.co.uk/gp/product/1932394923?ie=UTF8&amp;tag=daisramblin-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=1932394923">NHibernate in Action</a><img class=" luqmsfcfqseksqyogrfs" style="border:none !important;margin:0px !important" src="http://www.assoc-amazon.co.uk/e/ir?t=daisramblin-21&amp;l=as2&amp;o=2&amp;a=1932394923" border="0" alt="" width="1" height="1" />.)</p>
<p>Let’s move on to creating the mapping file.</p>
<p><em>IMPORTANT:</em> When you add the mapping file to your project, make sure you set the Build Action to Embedded Resource!</p>
<p>I have created a Lookup.hbm.xml file, and the source is below:</p>
<div style="font-family: Courier New;font-size: 10pt;color: black;background: white">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;<span style="color: blue">&lt;?</span><span style="color: #a31515">xml</span><span style="color: blue"> </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot;<span style="color: blue"> </span><span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot;<span style="color: blue"> ?&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;<span style="color: blue">&lt;</span><span style="color: #a31515">hibernate-mapping</span><span style="color: blue"> </span><span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">urn:nhibernate-mapping-2.2</span>&quot;</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; </span><span style="color: red">namespace</span><span style="color: blue">=</span>&quot;<span style="color: blue">Entities</span>&quot;<span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;4</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">class</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Lookup</span>&quot;<span style="color: blue"> </span><span style="color: red">table</span><span style="color: blue">=</span>&quot;<span style="color: blue">dbo.sp_GetLookups</span>&quot;<span style="color: blue"> &gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;5</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">id</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Id</span>&quot;<span style="color: blue"> </span><span style="color: red">column</span><span style="color: blue">=</span>&quot;<span style="color: blue">Id</span>&quot;<span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;6</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">generator</span><span style="color: blue"> </span><span style="color: red">class</span><span style="color: blue">=</span>&quot;<span style="color: blue">native</span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;7</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/</span><span style="color: #a31515">id</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;8</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">EnDescription</span>&quot;<span style="color: blue"> </span><span style="color: red">column</span><span style="color: blue">=</span>&quot;<span style="color: blue">enDescription</span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;9</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">CyDescription</span>&quot;<span style="color: blue"> </span><span style="color: red">column</span><span style="color: blue">=</span>&quot;<span style="color: blue">cyDescription</span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;10</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">IsActive</span>&quot;<span style="color: blue"> </span><span style="color: red">column</span><span style="color: blue">=</span>&quot;<span style="color: blue">IsActive</span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;11</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">loader</span><span style="color: blue"> </span><span style="color: red">query-ref</span><span style="color: blue">=</span>&quot;<span style="color: blue">dbo.sp_GetLookups</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;12</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &lt;/</span><span style="color: #a31515">class</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;13</span>&nbsp;</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;14</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">sql-query</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">dbo.sp_GetLookups</span>&quot;<span style="color: blue"> &gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;15</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">return</span><span style="color: blue"> </span><span style="color: red">alias</span><span style="color: blue">=</span>&quot;<span style="color: blue">dbo.sp_GetLookups</span>&quot;<span style="color: blue"> </span><span style="color: red">class</span><span style="color: blue">=</span>&quot;<span style="color: blue">Lookup</span>&quot;<span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;16</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">return-property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Id</span>&quot;<span style="color: blue"> </span><span style="color: red">column</span><span style="color: blue">=</span>&quot;<span style="color: blue">Id</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;17</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">return-property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">EnDescription</span>&quot;<span style="color: blue"> </span><span style="color: red">column</span><span style="color: blue">=</span>&quot;<span style="color: blue">enDescription</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;18</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">return-property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">CyDescription</span>&quot;<span style="color: blue"> </span><span style="color: red">column</span><span style="color: blue">=</span>&quot;<span style="color: blue">cyDescription</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;19</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #a31515">return-property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">IsActive</span>&quot;<span style="color: blue"> </span><span style="color: red">column</span><span style="color: blue">=</span>&quot;<span style="color: blue">IsActive</span>&quot;<span style="color: blue">/&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;20</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/</span><span style="color: #a31515">return</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;21</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; exec dbo.sp_GetLookups</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;22</span>&nbsp;<span style="color: blue">&nbsp;&nbsp;&nbsp; &lt;/</span><span style="color: #a31515">sql-query</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;23</span>&nbsp;<span style="color: blue">&lt;/</span><span style="color: #a31515">hibernate-mapping</span><span style="color: blue">&gt; </span></p>
</div>
<p>&nbsp; </p>
<p>To put it quite simply, lines 5 to 13 map my Lookup class to the columns in the stored procedure, while lines 16 to 20 map the results from the stored procedure my lookup class. Line 22 names the stored procedure. I am not sure if this is the best way to achieve the mappings, so any feedback would be appreciated.</p>
<p>Once your object is nicely  mapped, you then need to update your fluent configuration. All you need to do is tell FNH to load hbmMappings from the current assembly. See the snippet below:</p>
<div style="font-family: Courier New;font-size: 10pt;color: black;background: white">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;1</span>&nbsp;&nbsp;&nbsp; .Mappings(m =&gt; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;2</span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m.HbmMappings.AddFromAssembly(<span style="color: #2b91af">Assembly</span>.GetExecutingAssembly());</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;3</span>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  m.FluentMappings.AddFromAssembly(<span style="color: #2b91af">Assembly</span>.GetExecutingAssembly());</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;4</span>&nbsp;&nbsp;&nbsp;&nbsp; })</p>
</div>
<p> &nbsp; </p>
<p>To retrieve the list of lookups, I do the following, which populates my results variable with a list of all my lookups.</p>
<div style="font-family: Courier New;font-size: 10pt;color: black;background: white">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;1</span>&nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> sessionfactory = CreateSessionFactory();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;2</span>&nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> session = sessionfactory.OpenSession();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp;&nbsp;&nbsp;3</span>&nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> results = session.GetNamedQuery(<span style="color: #a31515">&quot;dbo.sp_GetLookups&quot;</span>).List();</p>
</div>
<p> &nbsp; </p>
<p>And that is it, the results variable now contains the list of lookups that I can use to populate my list control.</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2009/11/25/fluentnhibernate-and-stored-procedures/&amp;t=FluentNhibernate+and+Stored+Procedures&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2009/11/25/fluentnhibernate-and-stored-procedures/&amp;title=FluentNhibernate+and+Stored+Procedures&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2009/11/25/fluentnhibernate-and-stored-procedures/&amp;title=FluentNhibernate+and+Stored+Procedures&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=FluentNhibernate+and+Stored+Procedures;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2009/11/25/fluentnhibernate-and-stored-procedures/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2009/11/25/fluentnhibernate-and-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Want to show your source code to someone else?</title>
		<link>http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/</link>
		<comments>http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 15:47:13 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/</guid>
		<description><![CDATA[Today i stumbled across a nice tool called Pastie. Pastie helps you if you want to show some bits of your source code to someone else. e.g. you need some help, advice (or you just want to show off with your code). You paste an excerpt of your code and pastie saves it for under [...]]]></description>
			<content:encoded><![CDATA[<p>Today i stumbled across a nice tool called <a href="http://pastie.caboo.se/">Pastie</a>. Pastie helps you if you want to show some bits of your source code to someone else. e.g. you need some help, advice (or you just want to show off with your code). You paste an excerpt of your code and pastie saves it for under a unique URL. Then you send this URL to the person you want to show the code. The big advantage here is that the syntax is nicely highlighted &#8230; very nice for remote troubleshooting! I have created a <a href="http://pastie.caboo.se/129609">code snippet</a> for demonstration.</p>
<p><img src='http://www.webdevbros.net/wp-content/uploads/2007/12/pastie.jpg' alt='pastie.jpg' /><br />
(i&#8217;ve used <a href="http://pastie.caboo.se/help/">code sections</a> to create more sections.)</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/&amp;t=Want+to+show+your+source+code+to+someone+else%3F&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/&amp;title=Want+to+show+your+source+code+to+someone+else%3F&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/&amp;title=Want+to+show+your+source+code+to+someone+else%3F&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Want+to+show+your+source+code+to+someone+else%3F;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Toggle states like active, deleted, etc. (bitwise negation in SQL)</title>
		<link>http://www.webdevbros.net/2006/12/02/toggle-states-like-active-deleted-etc-bitwise-negation-in-sql/</link>
		<comments>http://www.webdevbros.net/2006/12/02/toggle-states-like-active-deleted-etc-bitwise-negation-in-sql/#comments</comments>
		<pubDate>Fri, 01 Dec 2006 23:00:05 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://fabiankoehler.de/wdb/?p=16</guid>
		<description><![CDATA[Just a little trick which might be useful. It's not new but I always enjoy using it and therefore its worth a quick post. In a lot of cases you find records in your database which hold a bit value 1/0 for fields like isActive, deleted, approved, etc. Usually they are toggled from 0 to [...]]]></description>
			<content:encoded><![CDATA[<p>Just a little trick which might be useful. It's not new but I always enjoy using it and therefore its worth a quick post. In a lot of cases you find records in your database which hold a bit value 1/0 for fields like isActive, deleted, approved, etc. Usually they are toggled from 0 to 1 or the other way round. Here comes a nice and quick solution to solve this toggling...<span id="more-16"></span></p>
<p>Let's say we have a bit field called "isActive" which holds 0 if the user is inactive and 1 if he/she is active. For our presentation we just want one button in order to achieve this state change and the underlying DB access should be done with one SQL statement if possible. Okay so here we go:</p>
<div class="igBar"><span id="lsql-2"><a href="#" onclick="javascript:showCodeTxt('sql-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">SQL:</span>
<div id="sql-2">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #993333; font-weight: bold;">TABLE</span><span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SET</span> isActive = <span style="color: #cc66cc;color:#800000;">1</span> - isActive</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color:#006600; font-weight:bold;">&#91;</span>condition<span style="color:#006600; font-weight:bold;">&#93;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Voila thats it, this SQL query toggles the isActive field of the user by using bitwise negation. The current state is being deducted from 1 and therefore 1 minus 0 results in 1 and 1 minus 1 in 0. Invert done! Needless to say, this solution is not limited to SQL and can be used everywhere where negation is needed.</p>
<p>I enjoy this solution because it's so handy. have fun! </p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2006/12/02/toggle-states-like-active-deleted-etc-bitwise-negation-in-sql/&amp;t=Toggle+states+like+active%2C+deleted%2C+etc.+%28bitwise+negation+in+SQL%29&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2006/12/02/toggle-states-like-active-deleted-etc-bitwise-negation-in-sql/&amp;title=Toggle+states+like+active%2C+deleted%2C+etc.+%28bitwise+negation+in+SQL%29&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2006/12/02/toggle-states-like-active-deleted-etc-bitwise-negation-in-sql/&amp;title=Toggle+states+like+active%2C+deleted%2C+etc.+%28bitwise+negation+in+SQL%29&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Toggle+states+like+active%2C+deleted%2C+etc.+%28bitwise+negation+in+SQL%29;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2006/12/02/toggle-states-like-active-deleted-etc-bitwise-negation-in-sql/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2006/12/02/toggle-states-like-active-deleted-etc-bitwise-negation-in-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

