Quantcast
Channel: { Name: "Mazin" }
Viewing all articles
Browse latest Browse all 25

ORM comparison: NHibernate loses to Entity Framework

$
0
0
I think that NHibernate is better than Entity Framework in several ways. Especially when it comes to NHibernate's ability to change the Code First model so easily without dropping and recreating the database. No data migrations, if you add a column to your model, a column is added to your database.

So it's easier in many ways, different in others, a little harder in others, but today I found a situation I was surprised that NHiberate simply loses to Entity Framework. The support to convert String.Contains to a Like expression is never a problem in Entity Framework in which you can use String.Contains on an entity in a LINQ expression built using a query or extension methods.

In NHibernate, using the String.Contains method results in an exception that says: "Unrecognised method call: System.String:Boolean Contains(System.String)"

To my surprise I had to create NHibernate.Criterion.ICriterion expressions similar to LINQ expressions.

var search = session.QueryOver<PersonHBN>()
                        .Where(new NHibernate.Criterion.AndExpression(
                            new NHibernate.Criterion.EqPropertyExpression("OtherEntity.id"NHibernate.Criterion.Projections.Constant(id)), 
                            new NHibernate.Criterion.LikeExpression("name"text)));

That was so much for just x.name.Contains(text)! But it is good to see that in NHibernate, there is an expression system that is similar to that of LINQ expression which is very powerful.

Viewing all articles
Browse latest Browse all 25

Trending Articles