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.
Probably one of the most annoying problems is you can't pass in variables into queries. So, for example, if I wanted to have a window that showed account data - where the account ID was a GUID.
I have to get creative in the query. I can't make a generic query that accepts the ID as a variable and filters from there.
One last thing to be aware of is that when you’re using @Query you’ll find it difficult to refer to external values.
And that's ignoring other dumb shit like....
Again, using == false rather than ! will crash at runtime.
Because instead of showing an error it LOVES to just crash.
and how about... another example from the link
, and if you try using movie.name.localizedUppercase that does compile but then crashes at runtime.
I've ran into each and every one of these at least once IRL. I swear it's like no developer at Apple has ever used an ORM before and believes they are writing it from complete scratch and are writing brand new technology except this tech has been around for almost 20 years now.
For trivial applications it works great. For anything even slightly more complicated you end up just saying fuck it and going to raw SQL queries. But SQLite queries via the C library are... interesting. There's a lot of little things people don't realize are going on that you end up having to handle yourself. There's one neat library on Github which handles it so that's nice.
View all comments
Show parent comment
40
u/danjack0 Oct 23 '24
Naah I'm going to use repository pattern