3

Possible Duplicate:
LINQ-to-SQL vs stored procedures?
Linq over Stored Procedures

What is the advantage while using LINQ than stored procedures ?

Community
  • 1
  • 1
Ullas Mathew
  • 133
  • 2
  • 5
  • 10
  • 1
    have you try [Google](https://www.google.com/search?q=advantage+of++linq+over+stored+procedure&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a)? – Usman Jan 10 '13 at 04:31
  • 1
    same question as – Sumit Jan 10 '13 at 04:33

2 Answers2

8

There are a lot:

  1. Debugging - It is really very hard to debug the Stored procedure but as LINQ is part of .NET, you can use visual studio's debugger to debug the queries.

  2. Deployment - With stored procedures, we need to provide an additional script for stored procedures but with LINQ everything gets complied into single DLL hence deployment becomes easy.

  3. Type Safety - LINQ is type safe, so queries errors are type checked at compile time. It is really good to encounter an error when compiling rather than runtime exception!

  4. Built-in security - One reason I preferred stored procs before LINQ was that they forced the use of parameters, helping to reduce SQL injection attacks. LINQ to SQL already parameterizes input, which is just as secure.

  5. Reduction in work - Before LINQ, I spent a lot of time building DALs, but now my DataContext is the DAL. I've used OPFs too, but now I have LINQ that ships with multiple providers in the box and many other 3rd party providers, giving me the benefits from my previous points.

NOTE: If all you're doing is simple INSERT, UPDATE, and DELETE statements LINQ is the way to go (in my opinion) and all the optimization is done for you, for more complex work I would say to stick with stored procedures.

For more detailed info, refer this: What is the advantage of LINQ over stored procedures?

Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
  • How we will manage a complex stored Procedure, for example one stored procedure calling with multiple stored procedure – Ullas Mathew Jan 10 '13 at 04:47
  • You will find more info regarding that over here: http://stackoverflow.com/questions/1716152/stored-procedure-calls-multiple-stored-procedures – Vishal Suthar Jan 10 '13 at 04:53
  • @VishalSuthar what's the OPF term? I searched the term but didn't find anything that made sense. – asd123ea Jul 12 '23 at 11:23
  • 1
    @asd123ea It stands for "Origin-Private File System" is an API providing browser-side persistent storage. – Vishal Suthar Jul 13 '23 at 10:36
0

If you google, you will find some SO question similar with your question.

You can see this linq-to-sql-vs-stored-procedures, linq-over-stored-procedures

Community
  • 1
  • 1
Iswanto San
  • 18,263
  • 13
  • 58
  • 79