Entity Framework Mapping Scenarios

The Entity Framework supports various ways to map conceptual models to relational data. For more information, see Modeling and Mapping.

The following 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 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 Walkthrough: Mapping and Entity to Multiple Tables and How to: Define a Model with a Single Entity Mapped to Two Tables.

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 Walkthrough: Mapping Inheritance - Table-per-Hierarchy and How to: Define a Model with Table-per-Hierarchy Inheritance.

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 Walkthrough: Mapping Inheritance - Table-per-Type and How to: Define a Model with Table-per-Type Inheritance.

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.

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: Create and Modify Complex Types.

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: Import a Stored Procedure and How to: Define a Model with a Stored Procedure.

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 Walkthrough: Mapping and Entity to Stored Procedures and How to: Define a Model with Modification Stored Procedures.

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.

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 (MSL). 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.

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.

For more information, see Association Element (CSDL).

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

See Also

Tasks

How to: Manually Define the Model and Mapping Files

Concepts

Entity Framework Resources
Working with Objects

Other Resources

Defining Advanced Data Models
ADO.NET Entity Data Model Designer
Defining Advanced Data Models
Samples