views:

174

answers:

4

I was checking 2nd edition of Professional ASP.NET MVC and realized EF replaced LINQ to SQL. I am familiar to LINQ to SQL from the first book but I know nothing about EF. Anyway while reading the code, it seems like nothing has changed except the name. Same old repository, same old functions.

I did a little research. I know LINQ is not limited to SQL. Also EF is not limited Microsoft-familiy SQL servers. In this 2 year old question people are not happy with EF, saying it's overcomplicated and all. But now I'm reading same code under EF name. Only classes are generated with ADO.NET Entity Model insted of LINQ to SQL. I have this buzzword crisis, can anybody clear out the fuss about shiny EF features since it's the de facto standart ORM now?

+2  A: 

EF replaced LINQ to SQL

Lies.


Edit:

This question, and the many others like it on this site and the internet have a single common source.

EF users like to parade around one quote from Tim Mallalieu to try to rain on LinqToSql users.

In contrast, LinqToSql users do not parade around the contemporary Vote Of No Confidence thing in the face of the EF users.

What is it that EF users have against LinqToSql? Why must they defend their technology choice with such an ignorant campaign based on one sentence?

David B
While LINQ to SQL is still supported (and probably will be updated for a time), consider this quote: "...as of .NET 4.0 the Entity Framework will be our recommended data access solution for LINQ to relational scenarios." (Tim Mallalieu, Program Manager, LINQ to SQL and EF http://blogs.msdn.com/b/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx).
Stephen Cleary
recommended < replaced. Also - 2008 is ancient history, how does he feel today?
David B
"We expect that people will continue to develop with LINQ to SQL" (Tim Mallalieu 2008-12 http://reddevnews.com/blogs/data-driver/2008/12/microsoft-says-linq-to-sql-not-dead.aspx)
David B
@David: he expects them to continue to develop, but he doesn't expect they'll be using any new features, because there won't be any.
John Saunders
@John Saunders - same article: "After .NET 4.0 we have every intention of doing feature work in LINQ to SQL." (Tim Mallalieu)
David B
@David: denial vs. the river in Egypt: not going to happen in this economy. Get over it.
John Saunders
+3  A: 

Latest EF is lot more robust, and you're not forced into a designer driven pseudo-ORM experience (or a morass of config if you tried to do it without the designer). Your model can be POCO objects now instead of some designer driven partial class mangled bs that's intrinsicly coupled with designer driven code, you can get away from the designer entirely without feeling like you're swimming upstream, and in general it just feels like they have listened to the community or actually tried to emulate existing, battle-tested solutions instead of making a version for the "Morts" or whatever L2Sql was supposed to be.

kekekela
+2  A: 

EF came of age with v4.0. Before that, it was a bit of a pain to use, and I didn't recommend it. Now my recommendation is that all new LINQ-to-DB code use EF4.

As far as new features go, the LINQ part is actually quite similar to LINQ to SQL. But it's quite a different architecture: EF4 acts as a LINQ provider to an (EF) ADO.NET provider which then wraps another ADO.NET provider. So there's new things like Entity SQL (which I don't use), and EF supporting different underlying ADO.NET providers (which I do use).

The XML modeling system that EF uses allows more powerful mapping abstractions, as well. One that I use regularly is having different tables with the same primary keys mapping to an entity inheritance relationship; from what I understand, the only way to do this in LINQ to SQL is via a "selector column" (though I never tried this in LINQ to SQL).

Stephen Cleary
It's not strictly true that EF supports "any" ADO.NET provider... the provider has to explicitly support EF. This is not the case of the OLE DB, ODBC or Oracle providers, for instance. Actually, there are very few providers that *really* support EF.
Thomas Levesque
@Thomas: Thans for the clarification. I was under the impression that EF would work with any ADO.NET provider, and that the providers only had to write EF bits if they wanted *design-time* support. Guess I was wrong.
Stephen Cleary
Since each DBMS has its own SQL dialect, each provider needs to implement the translation of Linq queries to SQL
Thomas Levesque
I thought that LINQ to Entities was translated to Entity SQL, which was implemented using the ADO.NET provider APIs. Is that wrong?
Stephen Cleary
@Thomas: I did some more research, and you are correct. In addition to the Connection/Command/etc. abstraction of the ADO.NET providers, they added a SqlGen bridge component as well. That makes sense. Updated answer.
Stephen Cleary
+3  A: 

They are somewhat similar, and can be used in a very similar way, code-wise, but they have some important differences. Note that "LINQ" is not the same thing as "LINQ to SQL"; the EF also uses LINQ. Some notable differences are:

  • LINQ to SQL is largely SQL Server only, not so much by design as by implementation. The EF is designed to support, and does support, multiple DBs, if you have a compatible ADO.NET provider.
  • Out of the box, LINQ to SQL has a very poor story for DB metadata changes. You have to regenerate parts of your model from scratch, and you lose customizations.
  • The EF supports model features like many-to-many relationships and inheritance. LINQ to SQL does not directly support these.
  • In .NET 3.5, LINQ to SQL had much better support for SQL-Server-specific functionality than the EF. This is mostly not true in .NET 4; they're fairly similar in that respect.
  • The EF lets you choose Model First, DB First, or Code First modeling. LINQ to SQL, out of the box, really only supports DB First.
Craig Stuntz