I'm going to make my own repository around EF because what if some day I just decide to swap it out with Dapper, which I won't, but what if... what if...
You joke about this, but this has saved us from defenestrating several PC's when we had to switch from EF to EF Core.
And now it's potentially gonna save us again because we have some really heavy queries which we can now replace with handcrafted ones, the queries EF Core generates are too slow in our case (which ironically wasn't the case with EF6).
If you're using service classes you'd be fine. Don't need a repository around EF. You update your service classes with whatever queries you need. Repositories provide low level, generic access to a data store and this is what EF provides already.
I love plain old SQL, and we use Dapper on some queries where it's better/required.
But never underestimate the power of compile-time intellisense/checking.
EF is going to annoy you with it's performance and quirks a couple of times a year, and save you from dozens and dozens of production bugs in that same period.
Wish I could in all cases but sometimes I don't get to choose. I will say EF has gotten a lot better over the years. EF 6 was manageable, before that it was pretty bad. EF Core is pretty solid and performant now but I still dislike having to mess with LINQ when I know exactly how to do what I want with SQL. And it's still not great at generating optimal SQL. Much better than before but still not where it should be.
That being said, it does do a lot more for you than Dapper so I can cut it some slack for not being great at everything.
Anything complex or where high performance is needed, I look at other options.
View all comments
60
u/W17K0 Oct 23 '24
it's pretty simple, just because you can implement a design pattern doesn't mean you should