Michael said:
Seems to me like it a bit of a doomed technology. Why bother writing linq
when you can just write the SQL? Seems to me that the point of linq is to
give you sql like abilities on stuff that is *not* in a database.
var q = from c in ctx.Customer
group c by c.Country into g
select g;
have fun doing that in SQL
Anyway, Linq gives you the ability to utilize the entity model in your
code to query the DB without the details of the database. For one, you
don't need to write the low-level crap for parameter creation, nor do
you have to care about relationships, nullable FK's etc. You also don't
have to care about typo's as they'll get caught by the compiler.
For example, if I want to sort a list of orders on the country of the
related customer, I can do:
var q = from o in ctx.Order
orderby o.Customer.Country ascending
select o;
How 'customer' and 'order' are related, I don't care, it's taken care of.
As a person who has written a large O/R mapper and a full Linq provider
for that O/R mapper, I can tell you that Linq queries are much more
compact than the SQL it will end up in and therefore less complex than
the SQL it will produce.
Another benefit, although not related to Linq to Sql, is that you can
write generic queries without worrying the database details like 'is
this running on oracle?' etc., that's abstracted away for you. Or the
ability to use .NET methods inside the projection without any effort.
'Linq' isn't just the query, it's the whole pipeline from Linq query to
SQL query to resultset to projection engine to object materializer to
resulting object sequence. So comparing a linq query with a 'sql' query
is apples compared to oranges: you need a whole machinery to execute the
SQL query, to consume the resultset in whatever format, to materialize
objects and to send them back up to the caller in a usable format.
_THAT_ is something you have to write yourself IF you want to use SQL in
..NET code. Did you add that to the equation? Or better: did you realize
that writing that plumbing code is actually similar to writing your own
grid control because you think it's useless to use one off the shelve?
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website:
http://www.llblgen.com
My .NET blog:
http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------