Wednesday, April 4, 2018

[Change my view] I don't really see the need for an ORM solution like Entity Framework or Dapper

I realise that this is going to be an unpopular opinion, but after much deliberation (and fear of downvotes and scathing comments), I thought I'd post it anyway. Maybe someone can make me see the light!

So, I started using .NET back when it was at 1.1, and I don't remember there being any decent ORM frameworks out there at the time. A couple of years later, I gave Entity Framework a try. It was still in the beta/pre-release stage, and it was absolutely awful. I tried it again a few months ago and although much improved, it still wasn't enough to convert me. This was for a couple of reasons:

  1. I had seen various benchmarks, and it was generally slowest of the lot. Typically, plain ADO.NET was faster than any framework.

  2. I don't like the code-first approach (I know you can do database first with EF), as I like to have a DBA mindset when I'm creating my database. I like to use stored procedures for all CRUD operations as you get the benefit of compiled execution plans. I like to design my own schema, which (sometimes) might look nothing like object model I have in my code, especially if it offers better DB performance. When I'm DBA mode, I tend to spend more time perfecting the database design, adding the correct indexes etc. I guess what I'm getting at is that the database design is deliberate (and I hope) well thought out - it's not an afterthought, or just something that Entity Framework has spat out.

I'll be upfront and say that I haven't played too much with other frameworks.

Typically, in a project, I'll just use ADO.NET. I'll create a Data Repository which represents all of the operations that can be performed against the database. I'll also create a Unit of Work class, which clients will use (instead of the repository). The UoW class handles all of the orchestrations, transaction management etc. My repository normally has a whole bunch of helper functions, which drastically reduces code duplication.

All I'm left with is the mapping between ADO.NET and my business models. I've heard people argue that this is where an ORM shines - you don't need to write all of that boring code. But really, it takes me no time at all (I can add new tables/fields in minutes), and when a mapping fails, the exception generally points me directly to the problematic field. I've heard that this can be an issue with some ORM frameworks as the mapping is hidden with magic!

I honestly, and possibly mistakenly, believe that I can all of this set-up just as quick as it would take me if I was using something like EF, and in the end, I will have something that runs much faster.

What are your thoughts on this? Am I missing some fundamental point? Have I just not looked at the right ORM framework?

[Change my view] I don't really see the need for an ORM solution like Entity Framework or Dapper Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team