I have this code:
DbSet table = ...// stored reference
var items = from n in table where
n.Name.ToUpper().Contains(searchString
It does an extra Select
but Selects have no cost associated. You can see the estimated query plan and it would show 0%
cost in that. It does that because EF is compatible with various RDBMS systems like Oracle, SQL server and to ensure maximum compatibility it might be doing this.
However I do agree that Entity Framework generates UGLY sql. The example that you gave was a very simple Linq query and you'll see more of that ugliness when your queries start becoming complex.
1) While this may or may not answer your answer, I would say use a micro ORM like PetaPoco:
https://github.com/toptensoftware/PetaPoco
or Dapper.Net
https://github.com/SamSaffron/dapper-dot-net
I have been using it in one of my project and I am completely satisfied with the raw speed that you get with plain Ado.Net.
2) My 2nd suggestion would be always use stored procedure for atleast Select
statements. For inserts, updates and deletes you should probably use EF and take advantage of change tracking mechamism and that would save your time from writing tedious queries but atleast for Select statements you should try to use plain SQL and that gives you more freedom over what SQL is generated.