Why to prefer LINQ over SQL


There are still those who write old SQL statements for every (!) CRUD operation. If you’ve used SQL for many years, you may have become so accepting of it that you simply reject the better approach.

SQL is a very old language — invented back in 1974. Since then it’s been extended endlessly, but never redesigned. This has made the language messy — rather like VB6 or Visual FoxPro.  And don’t forget one thingin reality there is no  “SQL language” but many many different sub languages of SQL.  Not even between different database servers (PL/SQL, T-SQL) but also between different database versions of the very same manefacture!

So why to prefer LINQ over SQL?  Because LINQ…

  • is a significantly more productive querying language in C# or C++ style
  • breaks down a query into parts, and then re-use some of those parts
  • query relationships without having to join
  • SQL returns flat tuples while LINQ returns shaped/hierarchical data
  • parameterization is inline, typesafe, and highly readable
  • possibility for client-processing via AsEnumerable()saving CPU power of the DB server
  • static type safety – when refactoring: the compiler will tell you right or wrong
  • switching to a different database manefacturer is quite more easy

see: why LINQ beats SQL

but there’s still need for SQL in some cases like:

  • optimisation
  • locks
  • triggers

.