Condividi tramite


Entity Data Model Mapping Scenarios (Application Scenarios)

The Entity Framework supports various ways to map conceptual models to relational data in an Entity Data Model (EDM). For more information, see Data Modeling in the Entity Framework.

The following Entity Data Model (EDM) mapping scenarios are currently supported by the Entity Framework.

Mapping scenario Description

Simple mapping

In this mapping scenario, each entity in the conceptual model is mapped to a single table in the storage model. This is the default mapping generated by Entity Data Model tools. For more information, see the Quickstart (Entity Framework).

Entity splitting

In this mapping scenario, properties from a single entity in the conceptual model are mapped to columns in two or more underlying tables. In this scenario, the tables must share a common primary key. For more information, see How to: Define a Model with Single Entity Mapped to Two Tables.

Horizontal partitioning in the storage model

In this mapping scenario, a single entity type in the conceptual model is mapped to two or more tables with the same schema. The entity is mapped into the tables based on a condition defined in the mapping specification. For more information, see How to: Define a Model with Horizontal Partition in Storage Model. For more information on condition mapping, see Condition Element (MappingFragment).

Horizontal partitioning in the conceptual model

In this mapping scenario, multiple entity types in the conceptual model that have the same properties are mapped to a single table. A condition clause is used to specify which data in the table belongs to which entity type. This mapping is similar to table-per-hierarchy inheritance mapping. For more information, see How to: Define a Model with Table-per-Hierarchy Inheritance.

Table-per-hierarchy inheritance

In this mapping scenario, all types in an inheritance hierarchy are mapped to a single table. A condition clause is used to define the entity types. For more information, see How to: Define a Model with Table-per-Hierarchy Inheritance (Entity Framework).

Table-per-type inheritance

In this mapping scenario, all types are all mapped to individual tables. Properties that belong solely to a base type or derived type are stored in a table that maps to that type. For more information, see How to: Define a Model with Table-per-Type Inheritance (Entity Framework).

Table-per-concrete-type inheritance

In this mapping scenario, non-abstract types are each mapped to an individual table. Each of these tables must have columns that map to all of the properties of the derived type, including the properties inherited from the base type.

Multiple entity sets per type

In this mapping scenario, a single entity type is expressed in two or more separate entity sets in the conceptual model. Each entity set is mapped to a separate table in the storage model. For more information, see How to: Define a Model with Multiple Entity Sets per Type (Entity Framework).

Complex types

A complex type is a non-scalar property of an entity type that does not have a key property. A complex type can contain other nested complex types. Complex types are mapped to tables in the storage model. For more information, see How to: Define a Model with Complex Type (Entity Framework).

Function import mapping

In this scenario, a stored procedure in the storage model is mapped to a FunctionImport element in the conceptual model. This function is executed to return entity data using the mapped stored procedure. For more information, see How to: Define a Model with a Stored Procedure (Entity Framework).

Modification function mapping

In this scenario, stored procedures are defined in the storage model that insert, update, and delete data. These functions are defined for an entity type to provide the update functionality for a specific entity type. For more information, see Stored Procedure Support (Entity Framework).

Defining query mapping

In this scenario, a query is defined in the storage model that represents a table in the data source. The query is expressed in the native query language of the data source, such as Transact-SQL, when mapping to a SQL Server database. This DefiningQuery element is mapped to an entity type in the conceptual model. The query is defined in the store-specific query language. For more information, see How to: Add a Defining Query. When you use a defining query, updates cannot be persisted to the data source using the standard update process. Updates can be made by defining modification function mappings. For more information, see Stored Procedure Support (Entity Framework).

Query view mapping

In this scenario, a read-only mapping is defined between entity types in the conceptual model and relational tables in the storage model. This mapping is defined based on an Entity SQL query against the storage model that returns entities in the conceptual model. For more information, see QueryView Element (EntitySetMapping). When you use a query view, updates cannot be persisted to the data source using the standard update process. Updates can be made by defining modification function mappings. For more information, see Stored Procedure Support (Entity Framework).

AssociationSet mapping

Associations define relationships between entities. In a simple mapping with a one-to-one or one-to-many association, associations that define relationships in the conceptual model are mapped to associations in the storage model. The following more advanced association set mappings are also supported:

  • Many-to-many associations. Both ends of the association are mapped to a link table in the storage model.

  • Self association. This supports an association between two entities of the same type, such as an Employee with an association to another Employee.

  • Associations between derived types. This mapping supports an association between a derived type in one hierarchy and a derived type in a second hierarchy. For more information, see How to: Define a Model with Associations Between Derived Types (Entity Framework).

For more information, see Association (EDM).

For information about the mapping scenarios that are supported by Entity Data Model tools, see ADO.NET Entity Data Model Designer Overview.

See Also

Concepts

Entity Data Model Inheritance (Application Scenarios)
Entity Framework Resources
Query an Entity Data Model (Application Scenarios)
Program Entity Data Model Classes (Application Scenarios)
Define an Entity Data Model (Application Scenarios)

Other Resources

ADO.NET Entity Data Model Designer Overview
Programming Guide (Entity Framework)
Samples (Entity Framework)