How to: Map Entities to Database Tables

[This page is specific to the latest version of the Entity Framework. The latest version is available as the 'Entity Framework' NuGet package. For more information, see Entity Framework Releases and Versioning.]

This topic describes how to map an entity type to a database table by using the Entity Designer. The Mapping Details window enables you map an entity to one or more tables, define conditions for the mapping, and specify the column to property mappings.

Note

This topic focuses on how to map an entity type to a single database table. However, an entity type can be mapped to multiple database tables.

The following table describes the fields in the Mapping Details window when an entity type is selected on the design surface.

Name Description

Column

Contains an alphabetized list of all columns in the table.

Operator

Shows the mapping or condition operator.

Value/Property

Displays the entity property that is mapped to the column.

If the field is blank, this means that the column is currently not mapped to a scalar property.

When you click the field, it becomes a drop-down list that displays all the scalar properties.

To add a mapping

  1. Right-click an entity type on the design surface or in the Model Browser and select Table Mappings .

    The table mappings are displayed in the Mapping Details window.

  2. In the Mapping Details window, click Add a Table or View .

    The field becomes a drop-down list that contains all the tables in the storage model that are not already included in the current mapping.

  3. Select a table from the list.

    A Maps to <Table Name> node is added to the window. This node contains default mappings between table columns and entity properties.The wizard checks whether column names match property names. If they match, the default mapping is between the column and property of the same name.

    An additional Add a Table or View row appears underneath the new mapping node. This enables you to add another table to the mapping.

  4. Expand the Maps to <Table Name> node.

    You can use the Add a Condition option to add a condition. Conditions enable the mapping system to map a particular type in the hierarchy to or from rows in a table, based on the values of the selected condition columns. Entity types can define a set of conditions for each table to which they are mapped. For more information, see How to: Add or Delete Conditions.

    A Column Mappings node also appears.

  5. Expand the Column Mappings node.

    A list of all the columns in the table appears. The default properties (if any) to which the columns map are listed under the Value/Property heading.

  6. Select the column you want to map, and then right-click the corresponding Value/Property field.

    A drop-down list of all the scalar properties is displayed.

  7. Select the appropriate property.

  8. Repeat steps 6 and 7 for each table column.

To delete a table mapping

  1. Click the Maps to <Table Name> node.

    The field becomes a drop-down list.

  2. Select Delete .

To delete a column mapping

  1. Select the column that you want to map, and then click the Value/Property field.

    The field becomes a drop-down list.

  2. Select Delete .

Build Date:

2013-06-19