BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News What’s New in Entity Framework 4.0 Beta?

What’s New in Entity Framework 4.0 Beta?

This item in japanese

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.

The major improvements introduced in EF 4.0 are:

  1. Customization of Code Generation – Integration with the ADO.NET Entity Framework Designer and T4 Templates in Visual Studio to provide developer controlled code generation.
  2. 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.
  3. 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.
  4. 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:

N-tier Development

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:

  1. Infer what the state changes are that need to be applied from a disconnected graph.
  2. Communicate those changes to the persistence layer.

To help with that, EF 4.0 contains the following API calls:

  • ObjectContext.ApplyOriginalValues
  • ObjectStateManager.ChangeObjectState
  • ObjectStateManager.ChangeRelationshipsState

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.

Model First

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.

Lazy Loading

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.

POCO Support

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.

Rate this Article

Adoption
Style

BT