a simple object mapper for .NET
After listening to Hanselminutes show #262 I became curious and have looked a bit at Dapper to check what it really is.
First of all, it’s implemented as a single file you can drop in your project. It’s created for and at stackoverflow. I heard somewhere that it should be 400 lines, but it looks more like 1200. It’s nice that I can understand much of how the ORM works just by browsing this file. But there are a few methods with a lot of il.Emit, which I can just hope works fine.
Dapper works as an extension of the IDbConnection interface through extension methods. With the use of generics it can return typed objects otherwise it returns dynamic objects.
I thought that perhaps a simple ORM like this is only targeted to a single provider, but of course it uses ADO.NET, so all providers supported there should work with Dapper. But as I understand it, you write raw SQL, so it doesn’t help you if you want to switch provider. But how often do you really do that? And it also means that you don’t have to learn a new language.
The goal has been to create a really fast and simple mapper, and according to their benchmarks, they have succeeded to make it fast. I think I heard that stackoverflow first used Linq2sql and Dapper is 4 times faster than Linq2SQL and 13 times faster than Entity Framework for a SELECT statement with 500 rows to Poco’s in their test case.
Of course it has some limitations, for example it lacks a identity map, but I suppose it makes it a good fit when you use a CQRS architecture and separate commands and queries?
I like the simplicity, and the speed, so I might try it for real some day.