views:

1674

answers:

3

I've been reading on the blogosphere for the past week that Linq to SQL is dead [and long live EF and Linq to Entities]. But when I read the overview on MSDN, it appeared to me Linq to Entities generates eSQL just the way Linq to SQL generates SQL queries.

Now, since the underlying implementation (and since SQL Server is not yet an ODBMS) is still a Relational store, at some point the Entity framework has to make the translation into SQL queries. Why not fix the Linq to SQL issues (m:m relationships, only SQL server support etc.) and use Linq to SQL in as the layer that generates these queries?

Is this because of performance or EF uses a different way of transforming the eSQL statement into SQL?

It seemed to me - at least for my unlearned mind - a natural fit to dogfood Linq to SQL in EF.

Comments?

+12  A: 

It is worth noting that Entity Framework has (at least) three ways of being consumed:

  • LINQ to Entities over Object Services over Entity Client
  • Entity SQL over Object Services over Entity Client
  • Entity SQL using Entity Client command objects (most similar to classic ADO.NET)

Entity Client ultimately spits out a representation of the ESQL command (in a canonical, database agnostic form) which the ADO.NET Provider for the specific RDBMS is responsible for converting into store specific SQL. This is the right model IMHO as over the years a lot of time has been invested (and will continue to be invested) in producing great ADO.NET Providers for each store.

As Entity Framework needs to work with many stores and therefore many ADO.NET Providers there is less scope for them to easily optimise what the Entity Client generates on a per store basis (at least - thats where we are with v1). The LINQ to SQL team had a much smaller problem to solve - "works only with SQL Server" and hence could do store specific stuff more easily. I know the EF team are aware that there are cases where EF to SQL Server is producing TSQL less efficiently than L2S and are working on improving this for V2.

Interestingly this model allows new capabilities to be added between the Entity Client and the ADO.NET Provider for a store. These "wrapping providers" can add services such as logging, auditing, security, caching. This is discussed as a V2 feature over at http://blogs.msdn.com/efdesign/archive/2008/07/09/transparent-caching-support-in-the-entity-framework.aspx

If you look therefor at the bigger picture you can see that it would be horribly difficult and indeed restrictive to try and somehow retrofit L2S TSQL generation into the archiecture of the Entity Framework.

Eric Nelson
A: 

A big difference between Linq to SQL and Entity Framework is that EF implements the Entity Data Model specification (EDM), and there are other products that are built around the EDM, like ADO.NET Data Services (aka Astoria).

The EDM is now being used to extend the AtomPub in a new spec called Open Data Protocol (OData http://odata.org/), which is used to standarize CRUD on top of REST.

Max Toro
and that is why a lot of people think that Linq to SQL is better!
Ian Ringrose
+3  A: 

Actually, the EF does not generate EntitySQL when translating LINQ queries. In the EF we have a data structure-based representation for all queries called CQT or canonical query trees. Both the LINQ translator and the EntitySQL parser produce CQTs, and the rest of the query translation pipeline uses CQTs (and other internal intermediate forms), which after various transforms make it to the ADO.NET provider (as a store-level CQT), which is then responsible for translating it to the backend's SQL dialect. So the paths are LINQ -> CQT -> SQL or EntitySQL -> CQT -> SQL.

Pablo Castro