C
C#14mo ago
Wycott

❔ Is Entity Framework still worth using

It has been a good 10 years or so since I used EF. From what I recall, it was good for code first and also for generating client side code directly from stored procedure outputs. Aside from that, there seemed to be few upsides for what seemed to be a fairly heavyweight ORM. I guess a lot has changed since those early days, and I understand EF is even a part of the .NET Core offering. Has anybody got any more recent experiences they would like to share?
42 Replies
Angius
Angius14mo ago
Entity Framework? No Entity Framework Core? Yes
JansthcirlU
JansthcirlU14mo ago
look into Dapper as an alternative
Angius
Angius14mo ago
If you like writing SQL queries by hand, then sure, look into Dapper If you never wish to see SQL again, use EF Core
Dropps
Dropps14mo ago
entity framework is the older and "bad" way to do things now entity framework core on the other hand is better but theres also things like dapper if you wanna write sql yourself which can be a pain sometimes
JansthcirlU
JansthcirlU14mo ago
migrations disagree
Dropps
Dropps14mo ago
i havent needed to touch migrations with sql ever even they are in c# code
Angius
Angius14mo ago
Never needed to touch them much either Just generate, apply, done
JansthcirlU
JansthcirlU14mo ago
you're still writing SQL inside the C# methods though
Dropps
Dropps14mo ago
except when you rename a table and change a type of it at the same time
Angius
Angius14mo ago
And even if I had to edit some migration, it's written in C#, with barely any SQL here and there
JansthcirlU
JansthcirlU14mo ago
and you need to know what the migrations mean if you want to debug in case something doesn't go right
Dropps
Dropps14mo ago
thats LINQ not sql
JansthcirlU
JansthcirlU14mo ago
no, your migrations have Up and Down methods that contain the SQL necessary to do the migrations
Dropps
Dropps14mo ago
no? thats all c#
JansthcirlU
JansthcirlU14mo ago
listen, I'm not saying EF Core is bad, on the contrary but Dapper is worth checking out especially when working closer to the metal
Dropps
Dropps14mo ago
ef core provides methods to execute raw sql as well
JansthcirlU
JansthcirlU14mo ago
yeah but it's a waste to use EF Core for that either use EF Core to its full extent or stick with Dapper to quickly bash out results
Dropps
Dropps14mo ago
also with dapper you are forced to write repositories if you want it easy to use ef core and repositories is a very dividing opinionated topic
JansthcirlU
JansthcirlU14mo ago
you can make it as easy or as abstract as you want okay my bad, they are indeed C# methods that just happen to execute 1-to-1 SQL queries
JansthcirlU
JansthcirlU14mo ago
stuff like character varying and bigint are things you have to know about the specific DB you're using so you do require the lower level knowledge to set-up EF Core like it or not
Angius
Angius14mo ago
Uh, not really? I just rely on NpgSQL's type mappings If it says it's a bigint, it's a bigint Whatever
Dropps
Dropps14mo ago
iam working with databases using ef core since 3 years and i still havent wrote a single line of sql in my life
JansthcirlU
JansthcirlU14mo ago
ok I corrected myself already, you're not literally writing SQL you're writing the C# version of them that pretty much follows the same syntax
Jimmacle
Jimmacle14mo ago
you aren't writing migrations by hand unless you need some weird custom behavior
JansthcirlU
JansthcirlU14mo ago
like drop table, hascolumntype whatever the heck
Jimmacle
Jimmacle14mo ago
the grand majority of the time you just make EFC generate the migration based on what you changed in your model and it just works
Angius
Angius14mo ago
dotnet ef migrations add ChangedSomeShit is how you write a migration lol
JansthcirlU
JansthcirlU14mo ago
yeah until it doesn't and you need to debug what happened
Jimmacle
Jimmacle14mo ago
that doesn't mean it isn't worth the time savings the rest of the time
JansthcirlU
JansthcirlU14mo ago
that's also not what I'm saying I've used both EF Core and Dapper, they have different use cases but saying you don't need to know or understand SQL because migrations are magic is untrue
Jimmacle
Jimmacle14mo ago
i'm not saying that either you shouldn't use EFC to avoid learning sql you should use it for the convenience and extra type safety it offers
JansthcirlU
JansthcirlU14mo ago
yeah well tell that to Drop and ZZZ
Angius
Angius14mo ago
I am using EFC to avoid learning SQL, besides the very basic concepts 😛
Jimmacle
Jimmacle14mo ago
several times i've had to debug issues by reading the actual queries being sent to the db
Angius
Angius14mo ago
Same But I feel like reading SQL and writing it are two different beasts SQL is not as much of a write-only language as Regex, but it's damn close
Mayor McCheese
Mayor McCheese14mo ago
I had an EF fight this morning. I won't go too much into that argument. I think that devs overall know less about sql than they should. It's less of an EF problem than a skillset problem.
JansthcirlU
JansthcirlU14mo ago
so what you're saying is skill issue
Jimmacle
Jimmacle14mo ago
i may or may not have been fighting EFC all day to get an overcomplicated solution to a simple problem working mostly my fault when
Mayor McCheese
Mayor McCheese14mo ago
For using ef
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?