Shifting directions…

Sometimes a refactor can be painful, but there is a light at the end of the tunnel, especially when you know the refactor will be a good move.

I really enjoyed working with Spring.NET but decided to shift to a simplier* model (Sharp Architecture).  A positive is that my code was separated well enough that the impact was minor.  (when I say ‘simplier’ – most that I’m only using a small subset of Spring.NET – NHibernate session management/Transactional management/Dao injection into my controllers)

One move led to another, and I made the jump to NHibernate 2.0.  While I was frustrated at being able to find the installer for NHQG 1.9 (there is one for 1.8 with NH 1.2) – I realized that the NHibernate direction is moving to NHibernate.Linq… so, hey, let’s try it out.

Let’s compare:

ICriteria:

            ICriteria crit = Session.CreateCriteria(typeof(EmployeeQuerySet))
                .Add(Expression.Like("LastName", lastName, MatchMode.Start));
            return crit.List<EmployeeQuerySet>();

 

NHQG:

return this.FindAll(Where.EmployeeQuerySet.LastName.Like(lastName, MatchMode.Start), OrderBy.EmployeeQuerySet.LastName.Asc);

 

NHibernate.Linq:

                        var query = from emp in Session.Linq<EmployeeQuerySet>()
                        where emp.LastName.StartsWith(lastName)
                        orderby emp.LastName ascending
                        select emp;

I personally like the Linq syntax because I’ve been using it since it was available to replace all my collection delegate calls.

So far so good on the refactoring…  🙂

(By the way, I really haven’t seen the value of something like EF or Linq to SQL when I have the power of NHibernate and NHibernate.Linq)

Learn more about NH 2.0 here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s