Entity Framework Improvements in .Net 4.0 – Summary & Links
May 13th, 2009 Posted in .Net, Betas, Entity Fraemwork, ado.net, microsoftI have used the entity framework in a few projects using .Net 3.5, but we were promised that there was much more to come in the next version which is shipping with .Net 4.0 and with quite a few announcements recently from the ADO.NET Team, I thought I would summarise and provide some links (at the bottom of the post) for you to get some more detailed info if you are interested.
Model First
This is something that I am really excited about and something that has long been needed IMHO.
In .Net 3.5 you could take a database and generate your entity framework model from it. In .Net 4.0 , however, it is possible to create your model first and then generate DDL for creating your database from your model.
This is all fantastic and I can see me using this method alot, but whats even better is the fact that you will also have the ability to customise the DDL generation step yourself to suit your own needs. For example, the default generation would be to generate a table per entity type, but you may have several entity classes that inherit from a parent class and in this instance you may want to modify the generator to produce a table per hierarchy structure for your database.
Deferred Loading
One of the things that people wish was available in the Entity Framework is deferred loading as it is in Linq to SQL. Well, now thanks to the ADO.Net team listening to the feedback, it is. Previously, if you had a Customer object that contained Orders for each customer, you needed to explicitly call a Load method on the Customer object to be able to use the Order objects associated with it.
Now though, the following is possible;
using (NorthwindEntities db = new NorthwindEntities()) { db.ContextOptions.DeferredLoadingEnabled = true; foreach (Customer c in db.Customers) { if (c.Orders.Count > 10) { SendLoyaltyRewardToCustomer(c); } } }
In the simple example above, you will notice that you do not need to explicitly load any Orders, but simply set the DeferredLoadingEnabled flag to true (this is off by default, but apparently there are ways to change this).
General Entity Framework Improvements
The following is a list from a recent post on the ADO.Net Team Blog of other key improvements coming to the Framework in this version;
-
- Development Approaches
- Model First development – We’ve added functionality to the ADO.NET Entity Data Model designer to start from a Model and then have T-SQL and customized code generated.
- Testing applications that use the Entity Framework – Along with the patterns above we’ve added an interface, along with guidance, that enables better testability of applications that use the Entity Framework.
Architectural Concerns
- Persistence Ignorance – Enabling developers to use their own classes without needing to introduce interfaces or other elements specific to the Entity Framework.
- Applications Patterns – Discussing patterns like the Repository and UnitOfWork patterns with guidance on how to use them with the Entity Framework
- Building N-Tier applications with the Entity Framework – Adding API’s and templates that make building N-Tier applications with the Entity Framework much easier.
Entity Framework Improvements
- 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 Singularlization 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
- And much, much more
- Development Approaches
Useful Links
The ADO.Net team have said that they have many mroe detailed posts on the way in the next couple of weeks so it’s well worth keeping an eye on their blog. Plus, we should soon see a beta of Visual Studio 2010 and .Net 4.0 which should contain some of the aforementioned features. I will be posting here when that’s released so keep an eye out for that.
ADO.Net Team Blog Post regarding Deferred Loading
ADO.Net Team Blog Post reagrding Model First in EF
Tags: .NET 4.0, ado.net, eneity framework




1 Trackback(s)