Discussion:
SQL queries vs using EF and LINQ: which is more popular for new projects?
(too old to reply)
RayLopez99
2012-09-27 16:09:17 UTC
Permalink
I think by now you can safely say EF and LINQ have just about equaled writing SQL queries the old fashioned way, using DataSets and what not. Speaking from a Visual Studio IDE background. True or false? I would think it's probably 40% new-school vs 60% old-school. Not counting legacy code maintenance, just new projects going forward.

RL
Jeroen Mostert
2012-09-28 07:43:16 UTC
Permalink
Post by RayLopez99
I think by now you can safely say EF and LINQ have just about equaled
writing SQL queries the old fashioned way, using DataSets and what not.
Speaking from a Visual Studio IDE background. True or false? I would think
it's probably 40% new-school vs 60% old-school. Not counting legacy code
maintenance, just new projects going forward.
I think all of these things are for wimps, and use SqlCommand and
SqlDataReader directly on stored procedures.

DataSet and DataTable are awful memory hogs I only use in the case of
dynamic schemas. EF and LINQ to SQL (and other ORMs) are very nice for
people who don't like (or don't have the time) to learn SQL and how RDBMSes
work in general, but since I already know that, they don't offer anything
spectacular except for small projects where DB maintenance and query
performance aren't important. It also greatly speeds up CRUD application
development, but I don't do much of that, so I'm biased.

Although EF is moving forward on the performance and maintenance dimensions,
support for "plain old SQL" has also improved dramatically in VS 2012,
especially with the new database projects and local database support in SQL
Server 2012. I see room for an approach where an ORM like EF can switch
between generated direct statements (for flexibility) and generated stored
procedures (for performance and coarse security) at the programmer's
discretion, with the improved database tools to back this up.
--
J.
Erland Sommarskog
2012-09-28 14:35:47 UTC
Permalink
Post by Jeroen Mostert
I think all of these things are for wimps, and use SqlCommand and
SqlDataReader directly on stored procedures.
Really? I also stick to SqlCommand, but it's not beacuse I am a brave man.
Rather, things like LINQ and EF makes me scared, as I have no idea what is
generated behind the scenes. This is the no least important when there
are complaints about poor performance.

I will have to confess that I use DataTables and DataSets. Then again, I
hardly write any production-level data-access code in .Net.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
RayLopez99
2012-09-28 16:58:56 UTC
Permalink
Post by Erland Sommarskog
Post by Jeroen Mostert
I think all of these things are for wimps, and use SqlCommand and
SqlDataReader directly on stored procedures.
Really? I also stick to SqlCommand, but it's not beacuse I am a brave man.
Rather, things like LINQ and EF makes me scared, as I have no idea what is
generated behind the scenes. This is the no least important when there
are complaints about poor performance.
Thank you both. A question to both: what do you write production code in? And I understand the Microsoft team is working hard to increase performance in EF and .NET (the latest Visual Studio 2012 in .NET is much faster than previous versions say some). Then again, if you're a die hard fan of performance even an extra 10 millisecond lag is too great--for example the London Stock Exchange wrote a good version of a stock trading platform in .NET, then had to scrape it when they found out "program traders" needed a few more milliseconds faster performance otherwise they would move to the NYSE. An expensive mistake but for most places I would think .NET is more than good enough, especially for maintenance where a good portion of programming is done.

RL
Jeroen Mostert
2012-09-28 19:34:13 UTC
Permalink
Post by Erland Sommarskog
Post by Jeroen Mostert
I think all of these things are for wimps, and use SqlCommand and
SqlDataReader directly on stored procedures.
Really? I also stick to SqlCommand, but it's not beacuse I am a brave man.
Rather, things like LINQ and EF makes me scared, as I have no idea what is
generated behind the scenes. This is the no least important when there
are complaints about poor performance.
Both LINQ to SQL and EF have features for turning on logging of the commands
generated, and of course you've got profilers. Although you can still make
the argument that you don't *really* know what's generated unless you get to
100% code coverage, and MS could (and does) change the algorithms with new
releases, peeking behind the curtain is really not that hard. Both LINQ to
SQL and EF are strongly typed, meaning the code isn't dynamic: it's a fixed
set of SQL, you just can't immediately see it.

My main issue is that, at best I'll see that the code is efficient (great)
and at worst I'll see I need to stick in a stored procedure to compensate
for code that's not (and I hope you can use a stored procedure, otherwise,
have fun creating and maintaining query plan guides). So why not just cut
out the middleman and write SQL directly? I know how to do that, having a
computer program do it for me doesn't save me a lot of time.

That said, I don't write many things with a GUI. It's all service-oriented
backend stuff, many different services running on the same database. Dynamic
code generation is actively harmful, while stored procedures serve as a
logical interface and offer an extra layer of customization if you need to
patch something and can't modify the binaries.

If all I had to do all day is write CRUD apps that use their own databases
exclusively, I'd definitely use an ORM. Probably EF.
Thank you both. A question to both: what do you write production code
in?
You'll have to be more specific. In what language? What IDE? What state of
mind? Which clothes?

For me it's C#, VS 2012, bemused and smart casual, in that order. But I'm
not married to any of it.
And I understand the Microsoft team is working hard to increase performance
in EF and .NET (the latest Visual Studio 2012 in .NET is much faster than
previous versions say some). Then again, if you're a die hard fan of
performance even an extra 10 millisecond lag is too great--for example the
London Stock Exchange wrote a good version of a stock trading platform in
.NET, then had to scrape it when they found out "program traders" needed a
few more milliseconds faster performance otherwise they would move to the
NYSE.
Stock trading is an extreme example. For the most part, that doesn't even
involve databases all that much, as disk I/O is just *too slow*. You're
talking Complex Event Processing on ridiculous hardware with custom code.
Even garbage collection is suspect in environments like those. Time is quite
literally money.
An expensive mistake but for most places I would think .NET is more than
good enough, especially for maintenance where a good portion of
programming is done.
If you're talking pure database code, you're I/O bound anyway. Saving a few
microseconds in the app while your database spends milliseconds on
transactions isn't going to make the difference. If your app is interactive,
you're human-bound and your only perf concern should be making the UI
snappy. For the rest, as always, a good algorithm on a slow runtime will
beat a bad algorithm on a fast runtime every day. The remainder where it
finally starts to matter what language/runtime your code is in usually still
has its performance concerns dwarfed by its maintenance costs.

In short, language bigots can suck it.
--
J.
RayLopez99
2012-09-30 17:20:39 UTC
Permalink
On Friday, September 28, 2012 3:34:24 PM UTC-4, Jeroen Mostert wrote:

[good stuff]

Thank you J and Erland, that was informative.

RL

Erland Sommarskog
2012-09-28 21:36:40 UTC
Permalink
Post by RayLopez99
Thank you both. A question to both: what do you write production code
in?
T-SQL and Perl. And some C++.

This requires some qualification. When I write application code for my
client, I only write stored procedures. In the past, I have dabbled
left-handedly in VB6, but as they have moved to newer architectures,
this has left me wayside. I'm a database guy.

However, I also maintain a toolset that my client uses to build and
deploy their databases, and this toolset is implemented in Perl, since
Perl is language that lends itself to efficient development and scripting.
But "production" in this case is development and deployment.

I also maintain an SQL Server API for Perl, and part of this is written
in C++, since Perl is implemented in C/C++.
Post by RayLopez99
And I understand the Microsoft team is working hard to increase
performance in EF and .NET (the latest Visual Studio 2012 in .NET is much
faster than previous versions say some).
Maybe it is, but that is not what I had in mind. What I had mind is that
since you don't write the queries, it gets difficult to tune them. And
you may not be able to use all features in SQL Server. For instance, as
I understand, EF does still not support table-valued parameters. The
performance in the client layer is of course not without importance,
but there are few tools that are so powerful to make things to really
slow as a relational database management system. A poorly written query
not supported by any good indexes can run for days. Rewrte, add indexes, and
you have the answer in minutes or even faster.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
Loading...