Snap back to reality, oh, there goes the ORM

Published on Thursday, April 9, 2015

I find myself going down this rabbit hole every six months it seems. I get lured in by the promises of an ORM. First it was Castle’s Active Record, then Linq2SQL, then Entity Framework, finally I settled on NHibernate as it worked better than others and I just liked the feel of it all. Then I discovered Dapper, oh how I really like Dapper. Dapper provides just enough abstraction to ADO .NET that I do not have to fiddle with data adapters or readers, or build commands. It provides all the power of SQL that I find that I need and all the object mapping I could want.

The hardest issue that I have with Dapper after using an ORM that bites me every time is the easy resolution of related objects. The building of an object graph with an ORM is just an after thought until those N+1 issues creep up or you realize that you are retrieving so much extra cruft that you just don’t really need. The great part about Dapper is that those things have to be intentianal and at times feel really manual, however, I have found that execute the extra queries to build an object with relations is actually faster most of the time, and if it isn’t I do not take the penalty throughout the entire applicaiton.

Just had this on my mind and thought I would share. Hopefully the future me doesn’t keep falling in this, “It looks so easy” trap and I just stick with using a micro orm, that provides just enough.