Does LINQ To SQL provide faster response times than using ado.net and oledb? Does LINQ To SQL provide faster response times than using ado.net and oledb? sql-server sql-server

Does LINQ To SQL provide faster response times than using ado.net and oledb?


LINQ to SQL actually presents some alarming performance problems in the database. Basically, it creates multiple execution plans based on the length of the parameter you are using. I posted about it a while back on my blog LINQ to SQL may cause performance problems.

Now, is that to say that LINQ doesn't have a place? Hardly. LINQ definitely has a place in the development toolkit, just like stored procedures. Ultimately, you want to use stored procedures when performance is absolutely necessary and use an ORM tool in any other situation.

As far as inline SQL goes, there are ways to execute inline SQL so that the plan is only built once and is never recompiled. Most ORMs should take care of this aspect of performance tuning as well and using these methods is usually the safest way to execute your SQL since it forces you to use parameterized queries.

Like most database solutions, the right answer depends on the problem you're trying to solve. If you favor development speed over database/application performance, then using LINQ or another DAL/ORM tool is the best way to go. If you favor performance over ease of development, then using stored procedures and pure datasets is going to be your best bet. LLBLGen even provides a LINQ to LLBLGen layer so you can use LINQ to query LLBLGen's objects and have LLBLGen actually handle building your queries and avoid some of the downfalls of LINQ.


Your basic premise is flawed..

Inline SQL requires one to communicate with the database in a certain way that opens the database to injections.

No it doesn't. Hard-coding user-inputted values into a SQL statement does, but you could do that with store procedures as well.

Parameterizing your queries guards against injection attacks, but inline SQL can be parameterizing just as easily as stored procedures.

Inline SQL must also be syntax-checked, have a plan built, and then executed.

All Sql (SPs and inline) must be syntax-checked and have a plan built on their first call. Thereafter, the exact text of the request & the execution plan are cached. If another request with the exact same text (not counting parameters) is received, the cached execution plan is used.

So, if you hard-code values into inline SQL, the text won't match, and it will have to re-parse the query. However, if you use parameters, the text of the query will match, and you will get a cache hit. In which case, it wouldn't matter if the query in inline SQL or a SP.

In other words, the only problem with inline SQL is that it easy to do something that slow & insecure. But making inline SQL fast & secure is no more work that using a SP.

Which brings us to LINQ, which always using parameters, even if you hard-code the values into the LINQ statement, making "fast & secure" inline SQL trivial.

LINQ also have the advantage over SPs of having all your code in one spot, instead of scattered over two different machines.


If you're interested in benchmarking, Rico Mariani has an excellent 5-part study that covers the qualitative and quantitative differences.

He may be an MS guy, but he's known as a performance nut - his benchmarks are thorough and well thought out.