What are the pros and cons of using linq queries(along with an ORM like EF or linq2sql) VS. Stored Procedures(SQL server 2008) to query and update a data model? Performance? Speed? Etc...
More importantly: when it comes to querying databases, LINQ is in most cases a significantly more productive querying language than SQL. Compared to SQL, LINQ is simpler, tidier, and higher-level. It's rather like comparing C# to C++.
Stored procedures (SPs) are a better choice than views, but views are much better than SQL queries embedded in reports.
Advantages of Using LINQLINQ offers a common syntax for querying any type of data sources. Secondly, it binds the gap between relational and object-oriented approachs. LINQ expedites development time by catching errors at compile time and includes IntelliSense & Debugging support. LINQ expressions are Strongly Typed.
No it is not.
Linq is definitely more readable when you're in the code. Seeing a call to execute a sproc called "sp_GetSomething" doesn't tell you anything as a developer, unless you go and physically look at what the sproc does. seeing code like
var query = from c in db.TableName
where c.Name == "foo"
select c;
That tells you exactly what data is being pulled.
Stored procedures on the other hand do not require you to recompile the application if you decide to change the code. If you decide to suddenly change a "where
" clause or change the Order By
- changing a sproc is easy. Changing the Linq code could be more time consuming.
I'm sure there are plenty more, but these are two I've noticed.
There are 2 camps: for stored procs and against stored procs.
I've found that it is lack of experience that make people go one way or another. There are different kinds of shops where we develop.
In practice
I'm in a corporate shop so...
We (as a developer DBA team) frequently have to bail out ORM users in sister teams.
There are also more subtle issues such that:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With