Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Architecture
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
Bing
BizTalk
Book Excerpts
Build and Deploy
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Design Patterns
Development Process
Display Technologies
Distributed Computing
DotNetNuke
DSL
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
Internet Explorer 8.0
Interviews
iPhone
Iron Ruby
Java
Java Script
jQuery
LINQ
Linux
Mac OS X
MDX
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
Network
NHibernate
Object Oriented Development
Odata
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Python
Q&A
Rails
Rake
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Search
Security
Services
SharePoint
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
Tips
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WF
Whitepapers
Windows 7
Windows Azure
Windows Live
Windows Server
Windows Vista
WinForms
Workflow
WPF
XAML
XML
XNA
XSLT



INSTANTLY dtSearch® TERABYTES OF TEXT


 


INSTANTLY dtSearch® TERABYTES OF TEXT

Reader rating:
Article source: CoDe (2009 Nov/Dec)


Article Pages:  1  2 3 4 - Next >


What’s New in Entity Framework 4, Part 2: Modeling Changes

If you have been working with the ADO.NET Entity Framework, you have probably been extremely eager to get your hands on the next version that is now part of Visual Studio 2010 and .NET 4.0. Long referred to as “EF Version 2,” this version is now called Entity Framework 4 or EF4, to align with the .NET Framework 4.0 version.

Part 1 of this article appeared in the September/October 2009 issue of CODE Magazine and covered API changes. In that article, you will find details on:

  • T4 support for custom code generation
  • The new ObjectSet class
  • Lazy loading support
  • POCO support
  • Enhanced state management methods

EF4 also contains a lot of highly anticipated improvements to the Entity Data Model (EDM) designer as well as some very interesting additions to the EDM itself. This article will focus on these changes.

"
Model defined functions allow you to add functions that are based on items in the model.
"

Pluralization and Singularization by the EDM Wizard

In the Visual Studio 2008 EDM Wizard, entity names come directly from the names of the database table names from which the model is derived. The same is true for each entity’s EntitySet name (the wrapper for a set of entities) and the navigation properties. If you don’t manually fix up all of these names, coding with these entities can be very confusing. You could have a query like this:

from person in context.Person
where person.Address.Count()>0
select person;

The query would make more sense if the various pieces of the expression had the proper singular or plural names. By changing the EntitySet of the Person entity to the plural form, People, and changing the navigation property that points to all of the Address entities for that person to the plural form, Addresses, the query is more logical.

from person in context.People
where person.Addresses.Count()>0 
select person;

Fixing up the names in the model in the current version of Entity Framework (hereafter, EFv1), is a critical and oftentimes consuming step. If you have a model with a lot of entities in it, the process can be quite frustrating. Microsoft corrected this behavior in the new EF4 designer.

Figure 1 shows the wizard displaying some challenging table names to turn into entity, EntitySet and navigation property names. Some of the table names are singular and some are plural and many of them use words that need much more than the addition of an “s” to pluralize. Brewery, for example, becomes Breweries. Person becomes People. Conversely, some of the already plural table names need more than the removal of an “s” to turn them into a singular name. Addresses is an example of this.

Click for a larger version of this image.

Figure 1: Letting the EDM Wizard fix up entity names.

Click for a larger version of this image.

Figure 2: The model created by the EDM Wizard has worked out the proper singular and plural forms of entities and navigation properties.

Click for a larger version of this image.

Figure 3: The EntitySet name for the Person entity was correctly pluralized by the EDM Wizard.

Below the object list is an option, new to EF4, called Pluralize or singularize generated object names, which is checked by default. As shown in Figure 2 and Figure 3, when the model is generated, all of these names have been worked out. The names of the entities are all correctly singular; the EntitySet names are plural (e.g., People, Addresses, Breweries). Not only are the entity and entity set names worked out, but the navigation properties as well. Navigations that point to an EntityReference are all singular (e.g., Address.Person) and those which point to an EntityCollection are all plural (e.g., Person.Addresses).

&

By: Julia Lerman

Julie Lerman is a Microsoft MVP, .NET mentor and consultant who lives in the hills of Vermont. You can find Julie presenting on data access and other topics at user groups and conferences around the world. Julie blogs at thedatafarm.com/blog and is the author of the highly acclaimed Programming Entity Framework (O’Reilly Media). Follow Julie on twitter at julielermanvt.

jlerman@thedatafarm.com



Article Pages:  1  2 3 4 - Next Page: 'Complex Type Support' >>

Page 1: What’s New in Entity Framework 4, Part 2: Modeling Changes
Page 2: Complex Type Support
Page 3: Other Designer Enhancements
Page 4: Model Defined Functions

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
4 out of 5

5 people have rated this article.

      INSTANTLY dtSearch® TERABYTES OF TEXT

 

INSTANTLY dtSearch® TERABYTES OF TEXT