Cover Story: Get Ready for the Entity Framework

更新日:

「Cover Story: Get Ready for the Entity Framework」という記事が公開されています。

http://visualstudiomagazine.com/articles/2010/09/01/get-ready-for-the-entity-framework.aspx

以下、上記URLから本文を引用して紹介します。

The ADO.NET Entity Framework 4, updated and released alongside the Microsoft .NET Framework 4 in April, is emerging as the default way to do data access in .NET-based applications. With the second generation of Entity Framework and related tooling in Visual Studio 2010, the Microsoft data access technology is better positioned for enterprise-level projects with a host of new functionality that brings it more in line with other object-relational mapping (ORM) tools.

The protests have died down with version 2 and the question of whether to use the implementation of LINQ known as LINQ to SQL -- the lightweight ORM that Microsoft shipped in 2007 -- or the Entity Framework, has been put to rest. LINQ to SQL is still an option but Microsoft has indicated that the Entity Framework now supports much of the functionality offered in LINQ to SQL and the company isn't putting any more resources behind it.


The Entity Framework is becoming a core part of the Microsoft technology stack. It works with WCF Data Services, WCF RIA Services, ASP.NET Dynamic Data, ASP.NET MVC and Silverlight, which does not support ADO.NET data sets.

"You can use LINQ to SQL or use your own classes as long as you follow certain rules, but a lot of those technologies are depending on a model. Entity Framework provides that model and Microsoft has built them so that they will very easily use an Entity Data Model from Entity Framework," says Julie Lerman, an independent .NET consultant who specializes in data platforms.

The Entity Data Model (EDM) provides a uniform way for developers to work with data by specifying the data structure of a client application through business logic, namely entities and relationships.

EDM consists of a conceptual data model (domain), model-based storage structures and a mapping specification that connects the two. It exposes ADO.NET entities as objects in .NET, providing an object-layer for Microsoft LINQ. Using LINQ to Entities, Entity SQL or query builder methods, developers can write queries against the conceptual model and return objects.

"It does remove all of the data access code that we used to have to write," says Lerman, who finished the second edition of her book, "Programming Entity Framework" (O'Reilly, 2010) in August. The book was rewritten to cover the Entity Framework 4 and Visual Studio 2010.

The Entity Framework takes a different approach than a lot of typical ORMs because the model has a mapping layer, which allows developers to really customize the model, Lerman says. "It's not just a direct representation of the database and that's a really important distinction."

"The goal of the Entity Framework is to be an abstraction layer on top of your database, so in theory it's supposed to reduce complexity," says Steve Forte, chief strategy officer at Telerik, which offers a competing ORM tool called OpenAccess. "However, developers know how to build applications the traditional way -- data over forms -- so the Entity Framework is something new that needs to be learned and the jury is still out on whether the learning curve is worth it."

Enterprise-Level Framework
The Entity Framework 1, which shipped out of band in Visual Studio 2008 SP 1 and the .NET Framework 3.5 SP 1 after dropping out of the beta cycle, was only braved by early adopters. It was deemed unusable for enterprise projects by many developers based on feature limitations and lack of adequate support for n-tier architectures.

"Until the most recent version of the Entity Framework, you could not easily build n-tier applications with it," says Lenni Lobel, chief technology officer at Sleek Technologies Inc. and principal consultant at twenty-six New York. Lobel says he's stayed away from the technology for enterprise-level production, but thinks the Entity Framework 4 is now viable for n-tier apps.

Many of the advances in the Entity Framework 4 were driven by feedback from developers who already used ORM tooling, according to Lerman. It now supports n-tier architectures within the framework via API and T4 templates, such as self-tracking entities. Microsoft also added key functionality, such as support for foreign key associations, lazy or deferred loading, and Plain Old CLR Objects (POCOs). Go to VisualStudioMagazine.com/EF0910 for more on the Entity Framework and POCOs.

"To me, the most important enhancement is the ability to support self-tracking entities once they're disconnected from the object context, but there's still a lot of work to be done," says Lobel, who notes that the POCO template is now a separate download after the beta cycle.

The Entity Framework 4 and Visual Studio 2010 support Model-First development, offering a Generate Database Wizard to create the database and parts of the EDM (SSDL, MSL) from a conceptual model. An Update Model Wizard helps you update the EDM when the database changes.

The EDM Designer has had a lot of improvements, such as how it handles complex types, but Microsoft couldn't come up with a way for people to deal with large models outside of a "large canvas," a complaint from the Entity Framework 1. "If your model is so large -- lots of entities -- that it's problematic in the designer, then you should probably be breaking the model up anyway, rather than asking the designer to enable you to work with it," says Lerman.

The EDM Wizard in Visual Studio 2010, which is used to create a conceptual model from an existing database (reverse engineering) and provide the database connections to your app, now supports foreign key associations and pluralization, which is important if you want to follow any kind of naming conventions for your entities.

"Previously, you had do lots of modifications to the model afterward," Lerman explains.

The Microsoft Edge
A few months after its release, the Entity Framework 4 seems to be holding up in comparisons with longstanding open source ORM NHibernate.

-Blog

Copyright© fullvirtue.com プロダクトオーナー支援スペシャリストのBlog , 2024 All Rights Reserved.