O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mapping Objects to Entities

Once you have completed the Entity Data Model wizard, you have a basic Entity Framework model that enables you to query your database. However, you have definitely not seen all the benefits of using the Entity Framework. Exploring these benefits involves improving the conceptual model to better map to the desired structure.

Simple Mapping

The mapping created above left you with a very thin layer over the database. Each of the generated properties were identical to the field names, and the field names in the AdventureWorks database are not exactly “friendly.” Changing these to create more “Visual Basic–like” property names is a simple matter.

Select the sales order detail table in the model and open the Mapping Details pane of Visual Studio. If it is closed, you can open it by selecting View ⇒ Other Windows ⇒ Entity Data Model Mapping Details.

As shown in the Mapping Details pane in Figure 10.10, the SalesOrderDetail object maps to the SalesOrderDetail table, and each property maps to the field with the same name. By changing the Name property for each field in the Properties pane, you can create a mapping that better explains what some of the fields represent (for example SalesOrder.SalesOrderId to SalesOrder.ID).

Figure 10.10 Entity Mapping

10.10

In addition, once you've changed the mapping, the code used to access the types reflects the new mapping (see ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required