views:

349

answers:

2

Hello,

I want to plan a data access layer and I thought to use Linq. I read that linq has its problems with performance and that you could use stored procedures with linq. Should I use stored procedures with linq when planning my data access layer? Is it crucial for the performance? When should I use them? I know that stored procedures are essential for security but linq uses type safe queries so the only reason for stored procedures is performance.

Thanks,

Omri

+2  A: 

From what I have read, the server caches execution plans of queries generated through LinqToSql, so these queries will perform roughly the same way as would equivalent stored procedures. And if you use stored procedures, then you lose the advantages that you get by using LinqToSql, since your query logic will stay in the DB.

See Rico Mariani's blog series on LinqToSql performance for more, as well as this blog post.

Yaakov Ellis
+2  A: 

If you're just writing simple CRUD, stored procedures are unlikely to help you with performance. As far as I know, the execution path of a stored proc is pretty much the same as for a prepared statement - i.e. appropriately optimised and cached.

They make a big difference when you can do work entirely in the database which would otherwise involve multiple round-trips to the database (with network traffic and latency as well).

Where did you read that LINQ has performance problems? I know of one particular issue which is fixed by precompiling the query, but other than that I thought it was basically okay...

Jon Skeet
I searched LINQ and performance in google and found a bunch of links talking about this issue.As i understood LINQ is built on ADO.net so it can't be faster..Thanks,Omri
Omri
No, it won't be faster than plain ADO.NET - but you didn't ask about performance relative to ADO.NET. The main thing is that LINQ makes your code easier to manage with minimal performance costs.
Jon Skeet