In my organization we have to answer to a separate DBA group for decisions like using LinqToSQL . What do you see as some of the best reasons for using L2S rather than stored procedures.
views:
196answers:
7You would be moving functionality previously in the database into your application, which can be a good or bad thing. I think a strong argument for LinqToSQL is that it can allow you to possibly have faster turn-around times using Linq if you have to submit your request for stored procedures to the DBA group, wait for them to finish, and then work with them to test and iron out any issues. You could at least use Linq for basic data access, and then use stored procedures if needed (they can be helpful for relieving performance bottlenecks).
When using L2S, more control is under application developer. So, I would say, you can quickly fix something without involving additional communication to DBA group.
Other than reports which is very data centric, I rarely use stored procedure nowadays.
The Stackoverflow question, Linq to SQL vs Stored Procedures?, has some good points for both sides.
Using stored procedures you get more tight control over your queries and when performance matters this can be a plus. You can also make changes to the procedures without needing to re-compile and re-deploy which can be handy.
However, using LINQ you get type-safety, your DAL is easier to keep versioned and maintained along with your project, it is easier to test and better debugging support.
I think it boils down to code integration. Rather than having to look at stored procedures, you can simply look at the code in your application.
Take a look at this link... http://www.linqpad.net/WhyLINQBeatsSQL.aspx
I've also found the capability to build dynamic sql like LINQ queries to not appear so dynamic and rather easy to debug. For example, suppose that you have a search page with 10 different criteria/filters. If the user only filters on 2 of them, you can create an extension method to add a where filter on the query if some condition is true. If you had a sproc, you'd have a heap of a mess to debug...
It will prevent against SQL Injection as well.
Sprocs do too, but the DBAs will be concerned about this if you are using linq2sql, so letting them know this will help in the convincing of letting you use L2S
L2S will also allow the DBAs to focus on optimization of the Database and its' table structures, indexes, etc and not have to worry about supporting any sprocs within the database, because that responsibility will be shifted to the dev team.
Check this out, sort of been discussed here:
http://stackoverflow.com/questions/14530/linq-to-sql-vs-stored-procedures
Also, we like to use linq for reading of data and stored procedures for the updating of data as there is some business logic in our sprocs (unfortunately). I don't agree with biz logic in sprocs however with the exception of the most rudimentary. There can be arguments for both sides and those would be relevant to your environment.