3

I'm more familiar with SQL raw queries. Most of the time I'm using stored procedure to do complex queries and Insert,Delete,Update and Select One record are done by using Simple Entity Framework methods and Linq queries. What are the Advantages and Disadvantages of using Linq and SQL Row queries and what is the best practice.

Sithira Pathmila
  • 145
  • 1
  • 3
  • 10
  • http://stackoverflow.com/questions/494816/using-an-orm-or-plain-sql – Habib Apr 07 '14 at 15:20
  • 2
    "Raw" SQL will most likely be faster (if you're good at writing SQL statements yourself), but Linq will be more efficient for programmer productivity (you get things done more quickly, have to write less boring and error-prone code) – marc_s Apr 07 '14 at 15:23

1 Answers1

3

SQL will almost always be (a lot) quicker as it is highly optimised towards the returning of specific sets of data. It uses complex indexing to manage knowing where to look for the data to be able to do this. This does however also often depend on your database maintenance. For example you can speed up the way your database searches by adding indexes to your databases, so as you can see, SQL requires more work than simply writing a stored procedure if you want to optimise the performance.

Linq on the other hand is a lot quicker to implement as opposed to SQL Stored procedures which tend to take longer to write and don't require you to perform maintenance on the data. Personally I find SQL difficult to read whereas Linq and programmatic code comes quite naturally to me.

Therefore I would say SQL is quicker and more tedious whereas the programmatic approach is slower but easier to implement.

If you are working on a small dataset you could probably get away with Linq, but if your working with a large database SQL is almost always the way to go.

CreativeAbyss
  • 313
  • 1
  • 18
  • 2
    Also do not forget not everything can be done in LINQ. I use EF for 80% of the work, but I regularly call into stored procedures that do things that I can not do in LINQ. Stuff like updating partitions or SQL with complex constructs that simply has no LINQ representation. Or -cough, sadly - hinting. Even lock hints are not supported by EF... shame. – TomTom Nov 11 '14 at 16:28