<?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>Emad Alashi&#039;s Blog &#187; NHibernate</title>
	<atom:link href="http://www.emadashi.com/index.php/category/development/nhibernate-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emadashi.com</link>
	<description></description>
	<lastBuildDate>Sun, 15 Jan 2012 10:05:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Case We Shouldn&#8217;t Use Stored Procedure&#8217;s In</title>
		<link>http://www.emadashi.com/index.php/2009/06/a-case-we-shouldnt-use-stored-procedures-in/</link>
		<comments>http://www.emadashi.com/index.php/2009/06/a-case-we-shouldnt-use-stored-procedures-in/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 12:51:18 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[Dynamic query]]></category>
		<category><![CDATA[subsonic]]></category>

		<guid isPermaLink="false">http://www.emadashi.com/index.php/2009/06/a-case-we-shouldnt-use-stored-procedures-in/</guid>
		<description><![CDATA[We are working on this big project at work in which several teams are assigned to different modules. The modules are, naturally, overlapping in certain areas where they they need to interact with each other through API&#8217;s.
One of these modules is central and crucial to the rest of the modules, the dependency is very high [...]]]></description>
			<content:encoded><![CDATA[<p>We are working on this big project at work in which several teams are assigned to different modules. The modules are, naturally, overlapping in certain areas where they they need to interact with each other through API&#8217;s.</p>
<p>One of these modules is central and crucial to the rest of the modules, the dependency is very high that the team has to provide many API&#8217;s. Certain API&#8217;s was needed by different modules; our team needed a list of entity X, and another team also wanted a list of entity X, BUT&#8230;we had different criteria!</p>
<p>For example, Entity X had an Enum property called &#8220;Type&#8221;. The API provided a parameter to filter on this Type, but the options were limited to couple of choices; either you get entities of THIS type, or you get all entities.&nbsp; If you needed type A and B only, you will have to get all the entities in the database, or make two hits to the database and join the two lists.</p>
<p>A solution was to give all the various options to the user as optional parameters some of which was Array of values. This resulted in an ugly API signature that had many optional parameters, and when ever a new criteria is needed, the signature would change and break all the already existing calls for the API, and I will not even imagine how the SP would look like!. An ugly alternative as well is to create new SP for each different criteria. Both choices are maintenance killers.</p>
<p>In such cases, the dynamic queries are just wonderful; depending on the properties the end user needs to filter on, a query will be created dynamically with proper operator passed. Usually <a href="http://en.wikipedia.org/wiki/Object-relational_mapping">ORM</a> engines, or similar engines, will provide you with an &#8220;internal language&#8221;, e.g. <a href="http://subsonicproject.com/">SubSonic</a>:<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br /><span style="color: #2b91af">Episode</span>&nbsp; ep = <span style="color: blue">new</span> <span style="color: #2b91af">Select</span>().From&lt;DA.<span style="color: #2b91af">Episode</span>&gt;().Where(<span style="color: #a31515">&#8220;Title&#8221;</span>).Like(<span style="color: #a31515">&#8220;SOA&#8221;</span>).ExecuteSingle&lt;DA.<span style="color: #2b91af">Episode</span>&gt;();<br />&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Another example is the &#8220;query by example&#8221; in <a href="https://www.hibernate.org/343.html">NHibernate</a> (code snippet is taken from NHibernate help):<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />IList episodes = session.CreateCriteria(typeof(Episode))<br />&nbsp;&nbsp;&nbsp; .Add( Expression.Like(&#8221;Title&#8221;, &#8220;SOA%&#8221;) )<br />&nbsp;&nbsp;&nbsp; .List();<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>And, of course, <a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx">LINQ</a>:<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
<pre>var episodes = from x in db.Episodes where x.Title.Contains("SOA") select c; ---------------</pre>
<p>Or you can build your own <img src='http://www.emadashi.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>I hope this gives an insight.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2009/06/a-case-we-shouldnt-use-stored-procedures-in/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Importance of Documentation</title>
		<link>http://www.emadashi.com/index.php/2008/12/importance-of-documentation/</link>
		<comments>http://www.emadashi.com/index.php/2008/12/importance-of-documentation/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 11:25:15 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Bunian]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[software management]]></category>
		<category><![CDATA[documentation]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/2008/12/26/importance-of-documentation/</guid>
		<description><![CDATA[&#160;
 
Lately we have decided in Bunian to move on to NHibernate 2.0, and the contributor assigned to the move started out, only to send an email one day after: &#8220;THERE IS NO DOCUMENTATION!&#8217;.We had errors as a result to the move which couldn&#8217;t be fixed without a documentation explaining why this happened.
After searching for [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><a href="http://eashi.files.wordpress.com/2008/12/documentation.jpg"><img style="border-width:0;" height="251" alt="documentation" src="http://eashi.files.wordpress.com/2008/12/documentation-thumb.jpg" width="174" align="right" border="0"></a> </p>
<p>Lately we have decided in <a href="http://www.codeplex.com/bunian">Bunian</a> to move on to NHibernate 2.0, and the contributor assigned to the move started out, only to send an email one day after: &#8220;THERE IS NO DOCUMENTATION!&#8217;.<br />We had errors as a result to the move which couldn&#8217;t be fixed without a documentation explaining why this happened.</p>
<p>After searching for a while, we found two resources of the new documentation:</p>
<ul>
<li>a wiki help that is hosted on <a href="http://knol.google.com/">Google Knol</a>: <br /><a title="http://knol.google.com/k/fabio-maulo/-/1nr4enxv3dpeq/21#" href="http://knol.google.com/k/fabio-maulo/-/1nr4enxv3dpeq/21#">http://knol.google.com/k/fabio-maulo/-/1nr4enxv3dpeq/21#</a><br />Not really appealing to be used extensively; no smooth flow between chapters, frames dazzle the eyes, no table of contents, but surely a great step forward for a documentation that is maintained by the community
<li>and online ordinary documentation as HTML: <br /><a title="http://www.nhforge.org/doc/nh/en/index.html" href="http://www.nhforge.org/doc/nh/en/index.html">http://www.nhforge.org/doc/nh/en/index.html</a> <br />which is my preferred way for documentation (or at least until the wiki proves its usability)</li>
</ul>
<p>Neither links were included anywhere in the NHibernate zipped file.</p>
<p>I didn&#8217;t realize how important a documentation is until it stopped us from moving on in our project; Only after we made sure that the documentation is available we decided to move on to version 2.0. The lesson to be learned is that if you are an enthusiast developer and want to add another piece of code to the world, keep in mind that your project is not only code; it is people, resources, community, ease of use, documentation, and any other simple thing that people need while you think it&#8217;s not important.</p>
<p>Of course I couldn&#8217;t find developers or contributors to open source projects greater than the NHibernate team, having such a project in the first place is awesome, and I thank each and everyone of them. I hope one day I can really contribute back to NHibernate. Thanks again guys.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/12/importance-of-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HttpApplication EndRequest Event Invoked Many Times In Single Request?</title>
		<link>http://www.emadashi.com/index.php/2008/12/httpapplication-endrequest-event-invoked-many-times-in-single-request/</link>
		<comments>http://www.emadashi.com/index.php/2008/12/httpapplication-endrequest-event-invoked-many-times-in-single-request/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 20:44:37 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Bunian]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ISession NHibernate EndRequest HttpApplication]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/2008/12/14/httpapplication-endrequest-event-invoked-many-times-in-single-request/</guid>
		<description><![CDATA[The other day I was putting the last touch of a temporary way to manage the NHibernate session (ISession) in Bunian. So part of the task was to bind a method to the HttpApplication EndRequest event (in the Global.asax.cs file) like the following:

public override void Init()
{
Â Â Â Â Â Â  this.EndRequest += WorkContext.NHibernateSessionManager.Instance.HttpRequestEnded;
}

By doing this, at the end of [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was putting the last touch of a temporary way to manage the NHibernate session (ISession) in <a href="http://www.codeplex.com/bunian">Bunian</a>. So part of the task was to bind a method to the HttpApplication EndRequest event (in the Global.asax.cs file) like the following:</p>
<div style="font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> Init()</p>
<p style="margin:0;">{</p>
<p style="margin:0;">Â Â Â Â Â Â  <span style="color:blue;">this</span>.EndRequest += WorkContext.<span style="color:#2b91af;">NHibernateSessionManager</span>.Instance.HttpRequestEnded;</p>
<p style="margin:0;">}</p>
</div>
<p>By doing this, at the end of each page request the <strong>NHibernateSessionManager.Instance.HttpRequestEnded()</strong> will be called and I can clean the session then. But to my surprise this method was called at least 10 times!! So I thought maybe the <strong>Global.Init() </strong>method is called many times for some reason and I ended up binding the same method to the EndRequest event many times, so I set a breakpoint at the Global.Init() method and&#8230;it&#8217;s called one time only.</p>
<p>That was strange, ok so it&#8217;s only the HttpRequestEnded() mehtod that is called many times, but I am requesting only one page!! how come there are 10 requests!</p>
<p>So I opened Firefox which is already &#8220;armed&#8221; with the magnificent add-on <a href="http://getfirebug.com/">Firebug</a>, and I requested the page again, Firebug showed the following:</p>
<p><a href="http://eashi.files.wordpress.com/2008/12/croppercapture1.jpg"><img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/12/croppercapture1-thumb.jpg" border="0" alt="CropperCapture[1]" width="664" height="272" /></a></p>
<p>And that was it!! the page contained 10 resources (1 CSS file and 9 images), OH! so <em>it is </em>one page, but for each resource referenced on the page you get a request, hence a raise of the EndRequest event.</p>
<p>I couldn&#8217;t love Firebug more; I am not only happy that I wasn&#8217;t doing something wrong, but yet I learned something new about the ASP.NET internals. awesome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/12/httpapplication-endrequest-event-invoked-many-times-in-single-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to NHibernate Session at Jordev Was Good</title>
		<link>http://www.emadashi.com/index.php/2008/12/introduction-to-nhibernate-session-at-jordev-was-good/</link>
		<comments>http://www.emadashi.com/index.php/2008/12/introduction-to-nhibernate-session-at-jordev-was-good/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 13:29:47 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[JorDev]]></category>
		<category><![CDATA[Presentation]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/?p=160</guid>
		<description><![CDATA[The feedback was very good, and I was glad that everybody liked it. Jordev is really moving ahead, and I am very excited being part of it  
Below is the slide show (it&#8217;s an enhanced version from my previous one):
[slideshare id=821222&#38;doc=introductiontonhibernate-1228487480885456-9&#38;w=425]
Code is the same of the previous one which you can download from here
]]></description>
			<content:encoded><![CDATA[<p>The feedback was very good, and I was glad that everybody liked it. Jordev is really moving ahead, and I am very excited being part of it <img src='http://www.emadashi.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Below is the slide show (it&#8217;s an enhanced version from my <a href="http://eashi.wordpress.com/2008/07/02/my-introduction-to-nhibernate-presentation-and-slides/">previous one</a>):</p>
<p>[slideshare id=821222&amp;doc=introductiontonhibernate-1228487480885456-9&amp;w=425]</p>
<p>Code is the same of the previous one which you can download from <a href="http://www.freedrive.com/file/395364,emadnhibernatepresentation.zip">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/12/introduction-to-nhibernate-session-at-jordev-was-good/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First Talk at JorDev .net</title>
		<link>http://www.emadashi.com/index.php/2008/11/my-first-talk-at-jordev-net/</link>
		<comments>http://www.emadashi.com/index.php/2008/11/my-first-talk-at-jordev-net/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 18:31:49 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[JorDev]]></category>
		<category><![CDATA[Presentation]]></category>
		<category><![CDATA[User Group]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/?p=157</guid>
		<description><![CDATA[Â  
JorDev .net is a .net user group founded by enthusiastic Jordanian IT professionals. On Wednesday the 26th of November I will be doing my first session of a series about NHibernate.
Details of talk is here:



Overview
NHibernate is an Object-relational mapping (ORM) solution for the Microsoft .NET platform. it provides an easy to use framework for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://eashi.files.wordpress.com/2008/11/jordevlogo.png"><img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/11/jordevlogo-thumb.png" border="0" alt="JordevLogo" width="215" height="113" /></a>Â  <a href="http://eashi.files.wordpress.com/2008/11/nhib-logo04.gif"><img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/11/nhib-logo04-thumb.gif" border="0" alt="nhib-logo04" width="211" height="126" /></a></p>
<p><a href="http://jordev.net/JordevCommunity/About.aspx">JorDev .net</a> is a .net user group founded by enthusiastic Jordanian IT professionals. On Wednesday the 26th of November I will be doing my first session of a series about NHibernate.<br />
Details of talk is here:</p>
<table border="1" cellspacing="0" cellpadding="2" width="720">
<tbody>
<tr>
<td width="165" valign="top"><strong>Overview</strong></td>
<td width="553" valign="top">NHibernate is an Object-relational mapping (ORM) solution for the Microsoft .NET platform. it provides an easy to use framework for mapping an object-oriented domain model to a traditional relational database. Its purpose is to relieve the developer from a significant amount of relational data persistence-related programming tasks.NHibernate is free as open source software that is distributed under the GNU Lesser General Public License</td>
</tr>
<tr>
<td width="166" valign="top"><strong>Target Audience</strong></td>
<td width="553" valign="top">.NET Developers, Software Designers, Software Engineers, Software Architects</td>
</tr>
<tr>
<td width="166" valign="top"><strong>Date</strong></td>
<td width="553" valign="top">Wednesday, November 26, 2008</td>
</tr>
<tr>
<td width="166" valign="top"><strong>Location</strong></td>
<td width="553" valign="top"><strong>MIC</strong> (Microsoft Innovation Center, Royal Scientific Society Building, 3rd Floor)</td>
</tr>
<tr>
<td width="166" valign="top"><strong>Time</strong></td>
<td width="553" valign="top">6:30 pm â€“ 8:30 pm (Amman-Jordan local time)</td>
</tr>
<tr>
<td width="166" valign="top"><strong>For More Info</strong></td>
<td width="553" valign="top">Mohamed Saleh @0788716457<br />
Ayman FaroukÂ Â Â  @0795727344</td>
</tr>
<tr>
<td width="166" valign="top"><strong>Reminders</strong></td>
<td width="553" valign="top">Â<br />
<img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/11/image006.gif" border="0" alt="image006" width="20" height="20" /><a href="http://calendar.live.com/calendar/calendar.aspx?rru=addevent&amp;dtstart=20081126T163000Z&amp;dtend=20081126T183000Z&amp;summary=NHibernate+Data+Access+Technology+Session+%5b1%5d&amp;location=Royal+Scientific+Society+Building%2c+3rd+Floor&amp;description=NHibernate+is+an+Object-relational+mapping+(ORM)+solution+for+the+Microsoft+.NET+platform.+it+provides+an+easy+to+use+framework+for+mapping+an+object-oriented+domain+model+to+a+traditional+relational+database.+Its+purpose+is+to+relieve+the+developer+from+a+significant+amount+of+relational+data+persistence-related+programming+tasks.%0a...%0d%0a%0d%0ahttp%3a%2f%2fjordevnhibernate1.events.live.com%2f">Live Calendar</a><br />
<img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/11/image002.jpg" border="0" alt="image002" width="34" height="15" /><a href="http://www.facebook.com/event.php?eid=45818242564">Facebook event</a><br />
<img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/11/image004.gif" border="0" alt="image004" width="20" height="20" /><a href="http://jordevnhibernate1.events.live.com/event.ics">Outlook Calendar</a><br />
<img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/11/image008.gif" border="0" alt="image008" width="20" height="20" /><a href="http://www.google.com/calendar/event?action=TEMPLATE&amp;text=NHibernate+Data+Access+Technology+Session+%5b1%5d&amp;dates=20081126T163000Z%2f20081126T183000Z&amp;location=Royal+Scientific+Society+Building%2c+3rd+Floor&amp;sprop=http%3a%2f%2fjordevnhibernate1.events.live.com%2f&amp;details=NHibernate+is+an+Object-relational+mapping+(ORM)+solution+for+the+Microsoft+.NET+platform.+it+provides+an+easy+to+use+framework+for+mapping+an+object-oriented+domain+model+to+a+traditional+relational+database.+Its+purpose+is+to+relieve+the+developer+from+a+significant+amount+of+relational+data+persistence-related+programming+tasks.%0a...%0d%0a%0d%0ahttp%3a%2f%2fjordevnhibernate1.events.live.com%2f">Google Calendar</a></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/11/my-first-talk-at-jordev-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NHibernate possible bug in IQuery.List&lt;T&gt;()</title>
		<link>http://www.emadashi.com/index.php/2008/09/nhibernate-possible-bug-in-iquerylistt/</link>
		<comments>http://www.emadashi.com/index.php/2008/09/nhibernate-possible-bug-in-iquerylistt/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 22:09:15 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[NHibernate IQuery bug IList]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/2008/09/22/nhibernate-possible-bug-in-iquerylistt/</guid>
		<description><![CDATA[recently, we had to clean the database from all the testing data, when an error similar to the following appeared:
The value &#8220;&#8221; is not of type &#8220;System.Nullable`1[System.DateTime]&#8221; and cannot be used in this generic collection
The code I executed was:

Â Â Â Â Â Â Â Â Â Â Â  IQuery query = DbManager.MySession.CreateQuery(&#8220;select max(dateObject.EndDate) from DateDomain dateObject&#8221;);
Â Â Â Â Â Â Â Â Â Â Â  IList&#60;DateTime?&#62; list = query.List&#60;DateTime?&#62;();

When I debugged NHibernate code, [...]]]></description>
			<content:encoded><![CDATA[<p>recently, we had to clean the database from all the testing data, when an error similar to the following appeared:</p>
<p><strong>The value &#8220;&#8221; is not of type &#8220;System.Nullable`1[System.DateTime]&#8221; and cannot be used in this generic collection</strong></p>
<p>The code I executed was:</p>
<div style="font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:#2b91af;">Â Â Â Â Â Â Â Â Â Â Â  IQuery</span> query = <span style="color:#2b91af;">DbManager</span>.MySession.CreateQuery(<span style="color:#a31515;">&#8220;select max(dateObject.EndDate) from DateDomain dateObject&#8221;</span>);</p>
<p style="margin:0;">Â Â Â Â Â Â Â Â Â Â Â  <span style="color:#2b91af;">IList</span>&lt;<span style="color:#2b91af;">DateTime</span>?&gt; list = query.List&lt;<span style="color:#2b91af;">DateTime</span>?&gt;();</p>
</div>
<p>When I debugged NHibernate code, I reached to the following AddAll() method in the ArrayHelper class:</p>
<div style="font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:#2b91af;">Â  152</span>Â <span style="color:#008000;">// NH-specific</span></p>
<p style="margin:0;"><span style="color:#2b91af;">Â  153</span>Â Â Â Â Â Â Â Â  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> AddAll(<span style="color:#2b91af;">IList</span> to, <span style="color:#2b91af;">IList</span> from)</p>
<p style="margin:0;"><span style="color:#2b91af;">Â  154</span>Â Â Â Â Â Â Â Â  {</p>
<p style="margin:0;"><span style="color:#2b91af;">Â  155</span>Â Â Â Â Â Â Â Â Â Â Â Â  <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">object</span> obj <span style="color:#0000ff;">in</span> from)</p>
<p style="margin:0;"><span style="color:#2b91af;">Â  156</span>Â Â Â Â Â Â Â Â Â Â Â Â  {</p>
<p style="margin:0;"><span style="color:#2b91af;">Â  157</span>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  to.Add(obj);</p>
<p style="margin:0;"><span style="color:#2b91af;">Â  158</span>Â Â Â Â Â Â Â Â Â Â Â Â  }</p>
<p style="margin:0;"><span style="color:#2b91af;">Â  159</span>Â Â Â Â Â Â Â Â  }</p>
</div>
<p>You can find the explanation of the error <a href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/abc99fb5-e218-4efa-8969-3d96f6021cee/">here</a>.<br />
Which brings us to the interesting question: why the implementation of IList Add method doesn&#8217;t consider the &#8220;nullability&#8221; of the T object? and why the parameter is of type IList ?!</p>
<p>Â Am I missing something? should I report it as a bug?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/09/nhibernate-possible-bug-in-iquerylistt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NHibernate Inverse attribute</title>
		<link>http://www.emadashi.com/index.php/2008/08/nhibernate-inverse-attribute/</link>
		<comments>http://www.emadashi.com/index.php/2008/08/nhibernate-inverse-attribute/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 14:22:26 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[attribute]]></category>
		<category><![CDATA[cascade]]></category>
		<category><![CDATA[Inverse]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/2008/08/22/nhibernate-inverse-attribute/</guid>
		<description><![CDATA[I had to read documentation, articles, many blog entries and go into discussions with colleagues&#8230; all to get the root of this ambiguous attribute of NHibernate, it is trickey!
This blog entry is another trial to explain the attribute, but with taking one more detailed step into the explanation.
NHibernate is meant to persist objects as well [...]]]></description>
			<content:encoded><![CDATA[<p>I had to read documentation, articles, many blog entries and go into discussions with colleagues&#8230; all to get the root of this ambiguous attribute of NHibernate, it is trickey!<br />
This blog entry is another trial to explain the attribute, but with taking one more detailed step into the explanation.</p>
<p>NHibernate is meant to persist objects as well as to manage their relations to each other, lets take a look at the following example of Parent and Child classes:</p>
<div style="font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Parent</span></p>
<p style="margin:0;">Â Â Â  {</p>
<p style="margin:0;">Â Â Â Â Â Â Â  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">int</span> Id { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="margin:0;">Â Â Â Â Â Â Â  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">string</span> Name { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="margin:0;">Â Â Â Â Â Â Â  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#2b91af;">IList</span>&lt;<span style="color:#2b91af;">Child</span>&gt; MyChildren { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="margin:0;">Â Â Â  }</p>
<p style="margin:0;">Â Â Â  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Child</span></p>
<p style="margin:0;">Â Â Â  {</p>
<p style="margin:0;">Â Â Â Â Â Â Â  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">int</span> Id { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="margin:0;">Â Â Â Â Â Â Â  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">string</span> Name { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="margin:0;">Â Â Â Â Â Â Â  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#2b91af;">Parent</span> MyParent { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
</div>
<p>and we have corresponding tables to these two classes like the following:</p>
<p><a href="http://eashi.files.wordpress.com/2008/08/parent.jpg"><img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/08/parent-thumb.jpg" border="0" alt="Parent" width="223" height="78" /></a></p>
<p><a href="http://eashi.files.wordpress.com/2008/08/child.jpg"><img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/08/child-thumb.jpg" border="0" alt="Child" width="222" height="101" /></a></p>
<p>(note 1: as we are proceeding that there is no Null constraint on the ParentId foreign key in the Child Table)<br />
Finally, we check the interesting part of the mapping files:</p>
<ol>
<li>Parent:
<div style="font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">bag</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">MyChildren</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">table</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">Child</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">cascade</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">all</span>&#8220;<span style="color:#0000ff;">&gt;</span></p>
<p style="margin:0;"><span style="color:#0000ff;">Â Â Â Â Â  &lt;</span><span style="color:#a31515;">key</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">column</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">ParentId</span>&#8220;<span style="color:#0000ff;">/&gt;</span></p>
<p style="margin:0;"><span style="color:#0000ff;">Â Â Â Â Â  &lt;</span><span style="color:#a31515;">one-to-many</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">class</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">Child</span>&#8220;<span style="color:#0000ff;">/&gt;</span></p>
</div>
</li>
<li>Child:
<div style="font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">many-to-one</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">MyParent</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">class</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">Parent</span>&#8220;<span style="color:#0000ff;"> &gt;</span></p>
<p style="margin:0;"><span style="color:#0000ff;">Â Â Â Â Â  &lt;</span><span style="color:#a31515;">column</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">ParentId</span>&#8220;<span style="color:#0000ff;">/&gt;</span></p>
<p style="margin:0;"><span style="color:#0000ff;">Â Â Â  &lt;/</span><span style="color:#a31515;">many-to-one</span><span style="color:#0000ff;">&gt;</span></p>
</div>
</li>
</ol>
<p>(note 2: all what the <span style="text-decoration:underline;">cascade=&#8221;all&#8221;</span> attribute in the MyChildren bag does is that when ever you save the Parent, all the Child objects in the MyChildren collection are forced to be saved as well; and we are only talking about the Save operation; not interfering or changing any of the values of the Child properties)</p>
<p>Now if we execute the following code:</p>
<div style="font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:#2b91af;">Parent</span> par = Session.Get&lt;<span style="color:#2b91af;">Parent</span>&gt;(8);</p>
<p style="margin:0;">Â Â Â Â Â Â Â Â Â Â Â  <span style="color:#2b91af;">Child</span> ch = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Child</span>();</p>
<p style="margin:0;">Â Â Â Â Â Â Â Â Â Â Â  ch.Name = <span style="color:#a31515;">&#8220;Emad&#8221;</span>;</p>
<p style="margin:0;">Â Â Â Â Â Â Â Â Â Â Â  par.MyChildren.Add(ch);</p>
<p style="margin:0;">Â Â Â Â Â Â Â Â Â Â Â  Session.Save(par);</p>
</div>
<p>As you may expect, both objects &#8220;par&#8221; and &#8220;ch&#8221; will be saved due to note 2 we mentioned above, but the surprise is that when you check the values in the database, you will see that the ParentId field was set as well although we didn&#8217;t set it explecitly in the code!</p>
<p><a href="http://eashi.files.wordpress.com/2008/08/dbvalues.jpg"><img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/08/dbvalues-thumb.jpg" border="0" alt="dbValues" width="244" height="43" /></a></p>
<p>The reason is that there is a hidden attribute called &#8220;Inverse&#8221; in the bag part of the Parent map file whose default value is &#8220;false&#8221;; when this attribute is set to false like the default value, then the Parent says: &#8220;Oh, so it is my responsibility to maintain the relationship with my child objects, ok then when ever a child is added to my collection, when I am saved&#8230;I will perform an update SQL statement to their foreign key to point at me&#8221;</p>
<p>So when the Save is called, the &#8220;par&#8221; object is saved, and the &#8220;ch&#8221; is inserted because calling Session.Save(object) when the object is new it will be inserted.Â  And after all that happens, an explicit update SQL statement will be executed to update all the child objects to set the foreign key ParentId to the par object Id.</p>
<p>This goes all fine in our case, only due to note 1 (scroll up again); we don&#8217;t have an Null constraint on the foreign key ParentId, so the Insert statement is excuted without exceptions, but in most cases in the world, DBA do put this constraint, by that we will get a &#8220;cannot insert Null value in ParentId&#8221; exception!</p>
<p>The solution is to set the Inverse attribute to &#8220;true&#8221;, which means that the Parent will NOT updated the Child objects foreign key, it will only call Session.Save(ch) due to the <span style="text-decoration:underline;">cascade</span> attribute, so the result will be like the record 6:</p>
<p><a href="http://eashi.files.wordpress.com/2008/08/dbvalues2.jpg"><img style="border-width:0;" src="http://eashi.files.wordpress.com/2008/08/dbvalues2-thumb.jpg" border="0" alt="dbValues2" width="244" height="62" /></a></p>
<p>But then how to solve this problem?! we want to set the value of ParentId AND be able to preserve the Null constraint; so we need to set the MyParent property of the Child to the Parent &#8220;par&#8221; like line 4:</p>
<div style="font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:#2b91af;">Â Â Â  1</span>Â <span style="color:#2b91af;">Parent</span> par = Session.Get&lt;<span style="color:#2b91af;">Parent</span>&gt;(8);</p>
<p style="margin:0;"><span style="color:#2b91af;">Â Â Â  2</span>Â Â Â Â Â Â Â Â Â Â Â Â  <span style="color:#2b91af;">Child</span> ch = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Child</span>();</p>
<p style="margin:0;"><span style="color:#2b91af;">Â Â Â  3</span>Â Â Â Â Â Â Â Â Â Â Â Â  ch.Name = <span style="color:#a31515;">&#8220;Emad&#8221;</span>;</p>
<p style="margin:0;"><span style="color:#2b91af;">Â Â Â  4</span>Â Â Â Â Â Â Â Â Â Â Â Â  ch.MyParent = par;</p>
<p style="margin:0;"><span style="color:#2b91af;">Â Â Â  5</span>Â Â Â Â Â Â Â Â Â Â Â Â  par.MyChildren.Add(ch);</p>
<p style="margin:0;"><span style="color:#2b91af;">Â Â Â  6</span>Â Â Â Â Â Â Â Â Â Â Â Â  Session.Save(par);</p>
</div>
<p>and to make it graceful, we can create custom collection for the Children and in the Add method of the collection we set the passed Child objects property MyParent to the parent.</p>
<p>You can download the code sample <a href="http://www.freedrive.com/file/461790,nhibernate_inverseatt.zip">here</a>.</p>
<p>I hope this is detailed enough to explain what the Inverse attribute exactly is, how to go about the Null exception, and to understand that the attributes &#8220;Inverse&#8221; and &#8220;cascade&#8221; are different things.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/08/nhibernate-inverse-attribute/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Mapping Enumeration of type int in NHibernate</title>
		<link>http://www.emadashi.com/index.php/2008/08/mapping-enumeration-of-type-int-in-nhibernate/</link>
		<comments>http://www.emadashi.com/index.php/2008/08/mapping-enumeration-of-type-int-in-nhibernate/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 07:45:38 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[Mapping]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/?p=74</guid>
		<description><![CDATA[I wanted to map an integer enumeration type in NHibernate, I googled &#8220;mapping enumeration in NHibernate&#8221; and the best explanation was of Jeremy Miller in his post here.
But as it appears (and according to my understanding) that the enumeration type should be mapped to a database column of characters type (varchar, char,&#8230;etc).
What if the database [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to map an integer enumeration type in NHibernate, I googled &#8220;mapping enumeration in NHibernate&#8221; and the best explanation was of Jeremy Miller in his post <a href="http://codebetter.com/blogs/jeremy.miller/archive/2006/02/20/138732.aspx">here</a>.</p>
<p>But as it appears (and according to my understanding) that the enumeration type should be mapped to a database column of characters type (varchar, char,&#8230;etc).<br />
What if the database column was int? well&#8230;do exactly like what jeremy did except simply use &#8220;<strong>NHibernate.Type.PersistentEnumType</strong>&#8221; instead of &#8220;<strong>NHibernate.Type.EnumStringType</strong>&#8220;.</p>
<p>The sole purpose of this post is that I didn&#8217;t find this solution fast enough on google, so I hope it helps others faster.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/08/mapping-enumeration-of-type-int-in-nhibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My &#8220;Introduction to NHibernate&#8221; presentation and slides</title>
		<link>http://www.emadashi.com/index.php/2008/07/my-introduction-to-nhibernate-presentation-and-slides/</link>
		<comments>http://www.emadashi.com/index.php/2008/07/my-introduction-to-nhibernate-presentation-and-slides/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 16:34:04 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/?p=39</guid>
		<description><![CDATA[I have delivered the presentation I talked about in my previous post here.
Actually it was pretty simple and straightforward, the slides them selves don&#8217;t have code content; all the code was shown in VS directly (I always found it better to see the code in its really environment to better understand).
The attendees were handful, but [...]]]></description>
			<content:encoded><![CDATA[<p>I have delivered the presentation I talked about in my previous post <a title="what is next" href="http://eashi.wordpress.com/2008/06/21/what-is-next-2/" target="_blank">here</a>.</p>
<p>Actually it was pretty simple and straightforward, the slides them selves don&#8217;t have code content; all the code was shown in VS directly (I always found it better to see the code in its really environment to better understand).<br />
The attendees were handful, but if felt really great when they expressed how excited they were about the whole thing.</p>
<p>You can find the Power Point slides and the sample code in the following zipped file:</p>
<p><a href="http://www.freedrive.com/file/395364,emadnhibernatepresentation.zip">http://www.freedrive.com/file/395364,emadnhibernatepresentation.zip</a></p>
<p>I intend also to share with you the process I went through in order to conclude to the presentation in its final state.</p>
<p>I hope you benefit from it <img src='http://www.emadashi.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span style="color:#ff0000;">Update: </span>I did this presentation again with enhanced slides, you can find those slides on <a href="http://eashi.wordpress.com/2008/12/05/introduction-to-nhibernate-session-at-jordev-was-good/">this post</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/07/my-introduction-to-nhibernate-presentation-and-slides/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Columns&#8217; case-sensitivity in NHibernate</title>
		<link>http://www.emadashi.com/index.php/2008/06/columns-case-sensitivity-in-nhibernate/</link>
		<comments>http://www.emadashi.com/index.php/2008/06/columns-case-sensitivity-in-nhibernate/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 09:29:44 +0000</pubDate>
		<dc:creator>Emad Alashi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://eashi.wordpress.com/?p=36</guid>
		<description><![CDATA[The other day I wanted to create an HQL query to retrieve data from one object (WorkOrderFault)Â that has many-to-many relation with another. so I created the following:

ISession session = NHibernateOrmSessionFactory.CurrentNHibernateSession;
IQuery query = session.CreateQuery(
Â Â  &#8220;select wof from WorkOrderFault wof join wof.WorkOrderTechnicians as tech where tech.Id = 43334&#8243;);
IList&#60;WorkOrderFault&#62; objects = query.List&#60;WorkOrderFault&#62;();

The query ran successfully, and I got [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I wanted to create an HQL query to retrieve data from one object (WorkOrderFault)Â that has many-to-many relation with another. so I created the following:</p>
<div style="font-size:11pt;background:#f2ebe3;color:black;font-family:Courier New;">
<p style="margin:0;"><span style="color:#2b91af;">ISession</span> session = <span style="color:#2b91af;">NHibernateOrmSessionFactory</span>.CurrentNHibernateSession;</p>
<p style="margin:0;"><span style="color:#2b91af;">IQuery</span> query = session.CreateQuery(</p>
<p style="margin:0;"><span style="color:#a31515;">Â Â  &#8220;select wof from WorkOrderFault wof join wof.WorkOrderTechnicians as tech where tech.Id = 43334&#8243;</span>);</p>
<p style="margin:0;"><span style="color:#2b91af;">IList</span>&lt;<span style="color:#2b91af;">WorkOrderFault</span>&gt; objects = query.List&lt;<span style="color:#2b91af;">WorkOrderFault</span>&gt;();</p>
</div>
<p>The query ran successfully, and I got my results.</p>
<p>Then I wanted to use paging and get certain amount of results starting from certain record, so I added these two lines directly after I instantiated the IQuery objectÂ :</p>
<div style="font-size:11pt;background:#f2ebe3;color:black;font-family:Courier New;">
<p style="margin:0;">query.SetMaxResults(10);</p>
<p style="margin:0;">query.SetFirstResult(0);</p>
</div>
<p><!--EndFragment-->Simple and nice, but instead I got the following error:</p>
<blockquote><p>System.Data.SqlClient.SqlException : The column &#8216;FaultId10_&#8217; was specified multiple times for &#8216;query&#8217;.</p></blockquote>
<p>When I checked my mapping file of WorkOrderFault, it had the following lines (I am including the lines we are interested in only):Â Â </p>
<div style="font-size:11pt;background:#f2ebe3;color:black;font-family:Courier New;">
<p style="margin:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">property</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">FaultId</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">type</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">System.Int32</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">column</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">FaultID</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">not-null</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">false</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">access</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">field.camelcase-underscore</span>&#8220;<span style="color:#0000ff;">/&gt;</span>Â </p>
<div style="font-size:11pt;background:#f2ebe3;color:black;font-family:Courier New;">
<p style="margin:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">many-to-one</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">Fault</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">class</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">GRP.Maintenance.Domain.Settings.Faults</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">column</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">FaultId</span>&#8220;</p>
<p style="margin:0;"><span style="color:#0000ff;">Â  Â  Â  Â  Â  Â  Â  Â  </span><span style="color:#ff0000;">fetch</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">select</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">insert</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">false</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">update</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">false</span>&#8220;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">not-found</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">exception</span>&#8220;</p>
<p style="margin:0;"><span style="color:#0000ff;">Â  Â  Â  Â  Â  Â  Â  Â  </span><span style="color:#ff0000;">access</span><span style="color:#0000ff;">=</span>&#8220;<span style="color:#0000ff;">field.camelcase-underscore</span>&#8220;<span style="color:#0000ff;">/&gt;</span></p>
</div>
</div>
<p><!--EndFragment--><!--EndFragment--></p>
<p>Ok, I know it&#8217;s wrong to map the same column for two different properties (don&#8217;t ask about the reason), but this is the current situation; one property to hold the Id (as an integer), and another property to hold everything. There might be more justifying situations where you want to map two properties to one column, so let&#8217;s assume it&#8217;s ok.</p>
<p>NHibernate is smart enough, when using queries, to query the database field only once; in situations like this NHibernate figures out that there are two properties mapped to one column so it shouldn&#8217;t retrieve it twice (i.e select columnx as x1, columnx as x2&#8230;..).<br />
But not in this case!! It just didnt&#8217; work!</p>
<p>I had no explanation for this, except when I looked closely to the map file, I noticed that the field that was causing the problem &#8220;FaultID&#8221; was written once with capital d (D), and the other with small d (d)!</p>
<p>So as it appears, NHibernate has schizophrenia when it comes to database columns case sensitivity; because SQL itself is case insensitive, but NHibernate code distinguishes between the uppercase and lowercase.</p>
<p>Keep an eye on your map files, try to make them EXACTLY the case like the database is, and unify that through all your map files.</p>
<p><span style="color:#ff0000;"><strong>UPDATE:</strong><br />
</span><span style="color:#000000;">the effect <strong>SetMaxResults()</strong>Â produced is it wrapped the original SQL sentace with &#8220;<span style="color:#3366ff;">WITH query AS (&#8230;</span>&#8220;, and only then the SQL refused the duplicate columns in the result, hence the SQLException took place.</span></p>
<p><span style="color:#000000;">original SQL: &#8220;<span style="color:#3366ff;">select workorderf0_.RecID as RecID10_, workorderf0_.WorkOrderID&#8230;.</span>&#8220;</span></p>
<p><span style="color:#000000;">SQL after SetMaxResults: &#8220;<span style="color:#3366ff;">WITH query AS (SELECT TOP 10 ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__,Â  workorderf0_.RecID as RecID10_&#8230;</span>&#8220;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emadashi.com/index.php/2008/06/columns-case-sensitivity-in-nhibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

