views:

302

answers:

2

I wanted to convert my existing stored procedures to LINQ-to-SQL Precompiled Dynamic SQL. Does anyone know of the best way to do this?

I mention precompiled as I believe I can get a performance increase - not the same as SPROC but similar, correct? Also with LINQ-to-SQL Precompiled Dynamic SQL, I get strongly typed fields, etc. Are these assumptions correct?

Also, it's probably not available, but is there a way to automatically convert my stored proceduress to LINQ-to-SQL?

+1  A: 

Converting all the stored procedures to LINQ to SQL will be a big job depending on how many stored procedures you have. What I would suggest and it is what we have done here is you set a date to start moving forward with LINQ to SQL instead of stored procedures. This way all new features will use LINQ to SQL and if you go back to an old feature and add new functionality than convert it to LINQ to SQL at that time.

You can also import your stored procedures into LINQ to SQL and use them like functions. Best way to approach this is to move slowly, one feature at a time and eventually you will be all converted.

As for performance gains, you might not see any huge gains right away. It will depend how optimized your stored procedures are? LINQ to SQL generates quite efficient SQL code but not in all cases and sometimes you will have to write some SQL to get the performance you require. I found that a lot of developers I worked with did not write very efficient SQL code in the stored procedures. Sometimes it was because of time constraints other times it was because they didn't know any better. In these cases LINQ to SQL tended to perform better because the SQL generates was much more optimized than what the developer could write them selfs. Another interesting point I have found is that LINQ to SQL tends to write much more efficient SQL than LINQ to Entities, just something to keep in mind.

Finally I am not aware of any tool that will convert your stored procedures into LINQ to SQL but the actual conversion isn't very hard, LINQ is very similar to SQL.

Hope this helps.

Lukasz
A: 

No, I don't agree with your assumptions.

1/ Stored Procedures will give at least as good, if not better, performance than LINQ-to-SQL. You won't see any performance increase by moving to LINQ-to-SQL

2/ You can get strongly typed fields using your existing stored procs. I believe you get this by using DataSets (from memory), but I am certain you will get it if you create a LINQ-to-SQL class and simply drag the Stored Procedures onto the designer. The code generator will create strongly typed and correctly named ReturnObjects for each Stored Procedure.

If you have existing Stored Procs then I wouldn't bother converting them to LINQ.

Kirk Broadhurst
Thanks, agreed, thanks again
mark smith