What’s New in Entity Framework 4.0 Beta?
Entity Framework 4.0 Beta 1 – aka EF V2 - delivered with .NET 4.0 Beta 1 contains a list of important improvements: Customization of Code Generation, Lazy Loading, N-tier Support, POCO Support, DDL Generation, Query Customization and others.
- Customization of Code Generation – Integration with the ADO.NET Entity Framework Designer and T4 Templates in Visual Studio to provide developer controlled code generation.
- Small things that make development of applications simpler – Adding things like Pluralization and Singularization in the model, lazy loading, and more stored procedure mapping make building applications that use the Entity Framework much easier.
- Customizing Queries – Adding support for existing LINQ operators, recognizing a larger set of patterns with LINQ, writing model defined functions along with the ability to use these in LINQ, and a number of other ways to create and customize queries.
- SQL Generation Readability Improvements – Improving the readability, along with TSQL performance optimizations, of the generated queries to make it much easier to understand what is happening
Detailing some of the improvements existing in EF 4.0:
One important aspect of N-tier development is the ability to exchange entity state between the server and the client. Diego Vega, Program Manager ADO.NET Entity Framework, details this further:
What you actually need is to:
- Infer what the state changes are that need to be applied from a disconnected graph.
- Communicate those changes to the persistence layer.
To help with that, EF 4.0 contains the following API calls:
Besides the low-level API, EF contains self-tracking entities:
Self-tracking entities know how to do their own change tracking regardless of which tier those changes are made on. As an architecture, self-tracking entities falls between DTOs and DataSets and includes some of the benefits of each.
The ADO.NET team will make available a T4 template (not included in Beta) to generate classes and extension methods for ObjectContext.
Visual Studio 2010 has to ability to generate a DDL and create a database to store the entity data model. The developer has complete control over the entire process being able to customize the DDL, or to select the database he desires, or fine tune the mapping process.
In EF 4.0 deferred/lazy loading of related entities is supported by default by setting the property ContextOptions.DeferredLoadingEnabled to true. Lazy loading works with code-generated entities as well as POCO ones. Lazy loading is turned off by default but this setting can be customized.
In .NET 3.5, EF objects needed to either inherit EntityObject or implement one of the interfaces: IEntityWithKey, IEntityWithChangeTracker andIEntityWithRelationships. That introduced strong awareness of the persistence layer spoiling the domain model. All these restrictions have been removed in EF 4.0 allowing for completely transparent persistence.