NHibernate 2.x Beginner's Guide
Monday, May 24, 2010, 12:47 PM - Programming, C#, VB.NET, ASPX, CodeSmith, NHibernate
My book is finally out! After over a year of more work than I ever thought it would take, I was finally able to hold a copy in my hand on Friday!

You can pick up the book at the publisher's website, and for $5 more you can have the PDF version also: https://www.packtpub.com/nhibernate-2-x-beginners-guide/book

If you prefer, you can also pick it up at Amazon or Barnes and Noble

If you're interested, you can take a look at a sample chapter here, just click on the "Sample Chapter" button.
  |  [ 0 trackbacks ]   |  permalink  |   ( 3 / 59 )
NHibernate 2.x Beginner's Guide
Monday, May 24, 2010, 12:46 PM - Programming, C#, VB.NET, ASPX, CodeSmith, NHibernate
My book is finally out! After over a year of more work than I ever thought it would take, I was finally able to hold a copy in my hand on Friday!

You can pick up the book at the publisher's website, and for $5 more you can have the PDF version also: https://www.packtpub.com/nhibernate-2-x-beginners-guide/book

If you prefer, you can also pick it up at Amazon or Barnes and Noble

If you're interested, you can take a look at a sample chapter here, just click on the "Sample Chapter" button.
  |  [ 0 trackbacks ]   |  permalink  |   ( 2.9 / 1298 )
NHibernate 2.0 works on MONO!!
Wednesday, August 27, 2008, 02:13 AM - 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!
  |  [ 0 trackbacks ]   |  permalink  |   ( 2.9 / 187 )
NHibernate 1.2 to 2.0
Wednesday, August 27, 2008, 02:03 AM - 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!
  |  [ 0 trackbacks ]   |  permalink  |   ( 3 / 209 )
Ordering by Calculated or Computed Fields in NHibernate
Thursday, November 22, 2007, 03:19 AM - 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.
  |  [ 0 trackbacks ]   |  permalink  |   ( 2.5 / 364 )

Next