NHibernate 2.0 works on MONO!!
Tuesday, August 26, 2008, 07:13 PM - Linux, .NET, NHibernate
Ok, so I'm probably not the first person to figure this out, but I'm ecstatic! Now I can upgrade to NHibernate 2.0 and start playing with the Fluent interface without having to maintain 2 separate sets of code![ add comment ] | [ 0 trackbacks ] | permalink |




( 2.9 / 187 )NHibernate 1.2 to 2.0
Tuesday, August 26, 2008, 07:03 PM - Linux, .NET, NHibernate
I took the opportunity to update one of my projects to NHibernate 2.0 today, because I want to start mapping with Fluent instead of XML. I took an existing working project and replaced the 1.2 references with the 2.0 replacements. This worked fine, except that the NHibernate.Expression namespace is now gone, replaced by the NHibernate.Criterion.
Once I replaced these using statements, I started getting a "Hibernate.MappingException : Could not compile the mapping document: <hbm.xml file> ----> System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary." error. It turns out, you have to call "config.Configure()" now, where this happened in 1.2 automatically.
Once I added this call to my Session Factories, the application reported that it could not find "hibernate.cfg.xml". I use mapping in my Web.Config instead of the XML file, so I figured this had changed. A couple of minutes with Google, and Viola! The Web.Config now looks like the xml configuration documents did in 1.2, which needs to look like this:
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string_name">connection_name</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="max_fetch_depth">0</property>
<property name="show_sql">true</property>
<property name="query.substitutions">true=1, false=0</property>
</session-factory>
</hibernate-configuration>
I did try replacing the name hibernate-configuration with another name (like "nhibernate" and it didn't work, so it looks like it needs to have that specific name).
I am now off to test it on Mono!
[ add comment ] | [ 0 trackbacks ] | permalink |




( 3 / 209 )Ordering by Calculated or Computed Fields in NHibernate
Wednesday, November 21, 2007, 08:19 PM - NHibernate
I got an interesting request the other day. Basically, the customer wanted to sort a query by a computed value. Simple ordering, say of a customer by name was not sufficient, something like:
criteria.AddOrder(Order.Asc(FieldNames.LastName));
would not work because they needed to sort based on a calculated field value (like x * y, or a + b). I found this link which describes this unique technique, basically creating a custom property for NHibernate to use to sort by.
private int _estimateDelta;
[Property(Formula = “PessimisticHours - OptimisticHours”)]
public int EstimateDelta
{
get { return _estimateDelta; }
set { _estimateDelta= value; }
}
Using this, you can add your sort just like normal:
criteria.AddOrder(Order.Asc("EstimateDelta"));
Simple as that.
[ add comment ] | [ 0 trackbacks ] | permalink |




( 2.5 / 364 )NHibernate Links
Friday, October 19, 2007, 10:37 AM - C#, NHibernate
Since I do so much work with NHibernate I thought it might be of interest to start maintaining a list of links related to this topic, so here they are, in no particular order:
Benjamin Day's blog on NHibernate
My NHibernate Data Layer Generation Project at Sourceforge
[ 2 comments ] ( 35 views ) | [ 0 trackbacks ] | permalink |




( 3.1 / 293 )Simple Class Example
Sunday, April 9, 2006, 11:02 AM - NHibernate, .NET, C#, CodeSmith, NHibernate
I recently saw a request for a simple class example that would link a Publisher, Author, and Book class to one another. Here is a Simple Class Test that highlights that example. Here are the Same Classes in VB. These classes are strikingly similar to the ones that NHibernate requires to work. I also have a set of CodeSmith templates to auto-generate this entire NHibernate data layer from a database...[ add comment ] | [ 0 trackbacks ] | permalink |




( 3 / 122 )Back






