Skip to main content
Jonathan Andrei
Sphera

Sphera

Data Developer

June 2021 - April 2022CanadaEnterprise environmental, health, safety and sustainability software

Cut production build time by 30% by rewriting the SQL an ORM was silently generating

C# and Entity Framework mapping specifications, rewritten so the generated SQL looked like something a DBA would actually recommend. Verified data integrity before and after so the win didn't quietly change behaviour.

C#.NETEntity FrameworkSQL Server

The problem

Production builds were slow enough to hurt developer productivity across the team. The existing data-access layer was making more round-trips than the queries required, and the default query shape Entity Framework generated was not the shape a DBA would have written by hand.

The approach

Developed mapping specifications in C# using Entity Framework to optimise the data access pattern.

Read the SQL Entity Framework actually generated behind the scenes, rewrote the mappings so the output looked like something a DBA would sign off on, and used efficient SQL to maintain and verify the data.

Verified data integrity before and after every change so the optimisation did not quietly change behaviour.

The outcome

Production build time down 30%.

Overall software development efficiency improved.

Behavioural equivalence held across the changed data-access surface.

What I take from this

ORMs quietly generate the query they are going to generate whether the shape is right or not. The 30% came from reading the actual SQL, not the C# that produced it. The same lesson applies to LLM-generated code today: read the output, not just the prompt.