Entity Framework does a great job to generate SQL. However, they are often very far to be optimized.
You don’t have to include everything in the same query, the divide and conquer strategy can apply here also!
People looking at the SQL generated often become speechless.
Did you really scroll down all the code to see all the SQL generated to execute this query?
Yes, this is what I call a monster SQL, and if you execute it, most columns will contains a NULL value which makes it even worse.
That’s for sure not the most optimized SQL, but it’s already way more readable.