473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

LINQ Queries vs Stored Procs

I've been looking at LINQ and it seems very nice to be able to make
queries in code, but I use stored procs for efficiency. If LINQ to SQL
only works with SQL Server and stored procs are more efficient, what
use is LINQ to SQL, other than to have a simpler way to call my stored
proc?
Jan 1 '08 #1
8 2601
I've been looking at LINQ and it seems very nice to be able to make
queries in code, but I use stored procs for efficiency. If LINQ to SQL
only works with SQL Server and stored procs are more efficient, what
use is LINQ to SQL, other than to have a simpler way to call my stored
proc?
Is that not enough?

Cor
Jan 2 '08 #2
Frank Calahan <ic***********@gmail.comwrote:
I've been looking at LINQ and it seems very nice to be able to make
queries in code, but I use stored procs for efficiency. If LINQ to SQL
only works with SQL Server and stored procs are more efficient, what
use is LINQ to SQL, other than to have a simpler way to call my stored
proc?
How convinced are you that your stored procs are actually improving
efficiency? If they're complex procs which are actually processing data
in a way that a simple SQL query wouldn't be able to then they will
indeed be helping - but if you've got stored procs for simple CRUD,
you're unlikely to be getting much benefit. (I believe stored procs and
parameterised queries go through much the same optimisation paths, are
cached etc.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jan 2 '08 #3
Jon,

AFAIK does the internal caching of the SQL server makes stored procedures a
very little bit more efficient.
(However that applies often used procedures)

Cor
Jan 2 '08 #4
On Jan 2, 11:49 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
AFAIK does the internal caching of the SQL server makes stored procedures a
very little bit more efficient.
(However that applies often used procedures)
What gets cached with stored procs that isn't cached with
parameterised queries?
I'm pretty sure the execution plan is cached for both...

I'd certainly be interested in hearing more information, of course.

Jon
Jan 2 '08 #5
Parameterized queries in SQL Server are cached and re-used, and there is
normally little difference in efficiency vs. stored procedures.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"Frank Calahan" wrote:
I've been looking at LINQ and it seems very nice to be able to make
queries in code, but I use stored procs for efficiency. If LINQ to SQL
only works with SQL Server and stored procs are more efficient, what
use is LINQ to SQL, other than to have a simpler way to call my stored
proc?
Jan 2 '08 #6
Hello Jon Skeet [C# MVP],

it depends on DB, but generally only queries/SP with the same params are
cached

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
JOn Jan 2, 11:49 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
Jwrote:
J>
>AFAIK does the internal caching of the SQL server makes stored
procedures a
very little bit more efficient.
(However that applies often used procedures)
JWhat gets cached with stored procs that isn't cached with
Jparameterised queries?
JI'm pretty sure the execution plan is cached for both...
JI'd certainly be interested in hearing more information, of course.
J>
JJon
J>
Jan 2 '08 #7
Michael Nemtsev [MVP] <ne*****@msn.comwrote:
it depends on DB, but generally only queries/SP with the same params are
cached
I understood it to be queries with the same parameter placeholders, but
not the same *values* of parameters.

(This can be a distinct disadvantage occasionally, if a query with one
parameter value should actually use a very different execution plan to
the same query with a different parameter value.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jan 2 '08 #8
Paul Shapiro <pa**@hideme.broadwayData.comwrote:
I think the security issue is the big one. If ALL data access is via Stored
Procedures, you can limit the user to only executing stored procedures,
without allowing read permissions on any tables. If you have well-defined
application roles, you can group users into role-based security groups and
assign the minimally-necessary permissions on the stored procedures.
True. Where that level of security is actually necessary, stored procs
are great. Where they're not, I think they're an extra overhead.
Stored
procedures eliminate most sql injection attacks, which are more possible
with dynamic sql.
Can you show me a SQL injection attack with LINQ to SQL, which is the
dynamic sql option here?
I personally prefer putting sql into stored procs instead of the application
because I find it a more effective way to organize the code. It separates
the database processing details from the application processing. But I think
that's just personal preference.
That sounds great in theory, but I think it adds an extra overhead if
you need flexibility of search. It can also be a real pain in cases
where you need really dynamic queries, e.g. allowing users to specify
multiple criteria in a flexible way.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jan 9 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Roy | last post by:
Hey all, Here's a small VB codeblock that connects to a database and uses 2 SQL queries then forms a relation for a master/detail view on the aspx side: Private Sub Binddata(ByVal name As...
7
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
4
by: Andy B | last post by:
Where would probably be the best place for queries to the database? in the db as stroed procs or in the dataSet.
2
by: Andy B | last post by:
Is there an easy way to convert tableAdaptor queries into stored procs without messing up the dataTables in the dataSet or losing the queries themselves?
1
by: hareen | last post by:
In LINQ stored procedures are Fast or LINQ Queries have Fast Access to Data Base
5
by: Andy B | last post by:
I was just wondering, when you create dataContext methods, should you put business logic there to try and minimize pushing data through 2-3 layers of code? or should the business logic still go in...
4
by: Jacek Jurkowski | last post by:
Why is it so slow? I really like that queries but using DataReader i have done my task's much more faster than ising LINQ...
6
by: Arjen | last post by:
Hi, My experience with linq is that I can develop my web application very fast. On the other hand, I have read that using stored procedures are executing faster. Is it smart to use linq for a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.