4 ms·
(probably) not many are using ORMs because "SQL is hard". You're attacking a strawman. I use ORMs because they make two things incredibly easy: - saving object
by 5e92cb50239222b 4y ago
(probably) not many are using ORMs because "SQL is hard". You're attacking a strawman. I use ORMs because they make two things incredibly easy:
- saving object graphs: it's trivial to write SQL for a simple CRUD form. It's far more difficult to work with real models where you have to deconstruct the form the user posted into a dozen tables with joins between them, doing insert/update/delete as needed. With a decent ORM you simply construct an object graph by assigning fields (the result can be very complicated), shove that into the database, and the ORM takes care of the rest. It may not be web scale™, but many of us don't need that.
- constructing queries on the fly: if you ever get any exposure to LINQ, I don't think you'll want to go back to SQL after that. It allows you to easily construct queries based on user input (in a type-safe way, unlike some other solutions), which saved me countless hours when building complicated tables with search and filtering on many (sometimes hundreds) of fields.
Here is a trivial example: https://stackoverflow.com/a/10884757 https://stackoverflow.com/a/10884757
And with good ORMs like Entity Framework the underlying queries they generate are predictable.
- Foobar8568 4y agoSo much this. I hate micro-ORM, they lost the relational part of RDBMS.
- ChymeraXYZ 4y ago> And with good ORMs like Entity Framework the underlying queries they generate are predictable. Right up until they are not and generate crap. I went from "predictable" EF generated queries to handcrafted ones reduced the load on the DB by about 70% while having more queries per second...
- asabla 4y agofrom personal experience this was a much larger problem during .net framework days. Now with EFcore, most generated queries are much more sane and performant
- sam_lowry_ 4y agoA very popular alternative is to inject json in the DB.
- chillfox 4y agoI only end up doing that when using an ORM to work around the limitations. I have never needed to do it when just using SQL.
- chillfox 4y agoI find that ORMs makes it significantly harder to construct queries for anything but the most basic of queries. I routinely end up having to fight the ORM.
- throwawaymaths 4y agoLinq is not really an orm, though. I think it's a "query builder"