Entity Framework & LINQ To SQL - Conflict of interest?

核能气质少年 提交于 2019-12-02 19:33:58

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!