3 ms·
This is partly why I love LINQ: it's a more C# flavoured way of expressing queries. And it works on objects as well as databases. Most ORMs are bad for queries
by pjc50 7y ago
This is partly why I love LINQ: it's a more C# flavoured way of expressing queries. And it works on objects as well as databases.
Most ORMs are bad for queries (pull over all the objects and look at their properties!), but LINQ will actually turn your code into SQL under the hood with some remarkable machinery.
- andybak 7y agoNot doubting there are bad ORMs but none of the ones I've dived into is quite that bad (SQL Alchemy and Django's ORM). I sometimes wonder if the debate about ORM is mainly driven by some traumatic horror witnessed at some point in every developer's career. If we judged programming languages by the same metric... Oh... Actually we kind often do that too!
- uhoh-itsmaciek 7y agoWhich ORMs are bad for queries? Most popular ORMs these days expose most of sql in a language-specific DSL (and some allow you to splice in bits of raw sql in a semi-structured way as an escape hatch). Sure, you still need to learn to "think in sql", to use these effectively, but the ORM has not been the problem for a long time in most languages.
- ratww 7y agoActiveRecord, Rails ORM was the poster child of ORMs for a while, and is completely abysmal for non-trivial left joins, non-trivial aggregations and some subqueries. Of course using raw SQL is possible but might force you into converting other parts of the code into raw SQL. There is Arel, but it's just a more verbose SQL in quasi-AST form. On the other hand, I never had much problems with LINQ or Hibernate.
- fernandotakai 7y ago>Most ORMs are bad for queries (pull over all the objects and look at their properties!) i would change that to ORMs CAN be bad for queries. most ORMs are super configurable and can be changed only to pull specific stuff. i would argue that most ORMs are a plus to productivity because for most of cases, you just need simple querying (select * from, simple updates, simple deletes). also, if you really need the power of raw sql you an just use that -- and even then, for most advanced ORMs (django's, for example) exposes a LOT of really advanced sql stuff in python, which, for a lot of developers, is a lot more expressive.