6 ms·
Right, which was my point. They used Linq to get around the limitations of an ORM more-so than using an ORM itself (by fetching an entity and accessing its 'fie
by entropicdrifter 22d ago
Right, which was my point. They used Linq to get around the limitations of an ORM more-so than using an ORM itself (by fetching an entity and accessing its 'field'). They're evading the N+1 problem by writing a query by hand still, just not in SQL itself.
The bit about lazy loading was a bit of a side-note more than my main point.
- fabian2k 22d agoBut using LINQ to query stuff is a core part of this ORM. And even if you access the full entity, it won't do an N+1 in the default configuration. You have to explicitly call Include() on any relation you want to fetch and it'll either fetch all of them with one query or do one query per relation type. There's a different footgun here with AsSingleQuery() and AsSplitQuery(), but that's a separate topic.
- imtringued 21d agoRemember kids, writing queries in an ORM is a betrayal to the ORM gods. You are supposed to manually count the question marks in your raw SQL like the JDBC gods intended. String sql = "INSERT INTO users (name, email, age, status, country) VALUES (?, ?, ?, ?, ?)"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, "Alice"); pstmt.setString(2, "alice@example.com"); pstmt.setInt(3, 30); pstmt.setString(4, "ACTIVE"); pstmt.setString(5, "US"); There is absolutely zero chance an ORM can ever get close to the performance of this query, so write it by hand! After all, the primary promise of ORMs has been that you do not have to write queries, it's right in the name! Object Relational Mapper!
- red_admiral 20d ago> You are supposed to manually count the question marks in your raw SQL like the JDBC gods intended. String sql = "INSERT INTO users (name, email, age, status, country) " + "VALUES (?, ?, ?, ?, ? )"; But I get your point.