tags:

views:

87

answers:

4

I hear a lot of linq-to-sql bashing and how people will unknowingly abuse it. But how is linq-to-sql being abused?

Update If someone can give me clear examples of how it's abused that would be very helpful. References to blogs/tutorials would be very helpful as well. Thanks.

+1  A: 

There are many ways that LINQ->SQL can be abused just like poorly written inline SQL/ADO.NET/SPs or what have you.

Alot of what you might have heard is how LINQ itself might be abused.

Quintin Robinson
A: 

Well... if you can write complicated queries with linq-to-sql it's probably because you know SQL syntax and are pretty good at writting the query in SQL in the first place. So why would you use the .NET syntax to write a syntax tree that then another layer of software would translate (perhaps not very efficiently) into SQL for you? Just write the damn thing in SQL in the first place :-)

Nestor
Why? Because it allows faster development in a single environment. And 'complicated' linq-to-sql queries are much simpler to write and more succinct than their sql counterparts.
Kirk Broadhurst
it's not a single environment. Your syntax gets converted to SQL for you. Also, there are constructs in SQL not incorporated into .NET syntax yet (c# or VB.net). So in a way using LINQ you might be under utilizing the SQL engine.
Nestor
burnt1ce
Kirk, care to explain why -2 for having a different opinion than yours?
Nestor
Not true. My SQL knowlege is very limited, but I can write pretty complex L2S queries. Maybe because I have a good understanding of the _concepts_ behind SQL (set theory). As a benefit, my queries are strongly typed, under source control and also on a (slightly) higher level of abstraction. I guess I could switch to SQL, but all it would give me are longer development times, so why bother?
nikie
+3  A: 

One of the easiest mistakes to make is to create a query which results in a loop of calls to the database instead of a single call returning all the data. For this reason it's worth checking what sql commands are hitting the database either in the debugger or with a trace.

FinnNk
+1  A: 

I think one example of it being misused would be as a total replacement for SQL in views or stored procedures on the server, and therefore potentially more lax security on the database server.

CodeByMoonlight