Entity Mapping

This topic describes how to map entities to database tables with Entity Developer. The Entity Mapping Details dialog box allows you to map an entity to one or more tables, define conditions for the mapping, and specify the column to property mappings.

Entity Developer also allows you to create a QueryView mapping. Query View can be used when default mapping from Entity Framework does not meet your needs, and you need more flexible mapping. For example, you may use Query View mapping to map a single entity to two tables connected with a one-to-one relationship, or to filter table records, etc. Query View is written in Entity SQL and can only query the tables defined in the storage model.

If you are using Query View mapping, you should map insert, update, and delete operations to stored procedures because Entity Framework is not aware of the query written inside QueryView.

 

ExpandedToggleIcon        Mapping an Entity to One or More Tables

To map an entity to one or more tables, do the following:

1.Right-click an entity on the diagram and select Mapping Details from the popup menu.
2.In the Storage Entities grid click <Add a Table or View> and select the table or view from the drop-down list.
3.In the Column Mappings grid click a row and select the property, corresponding to the table column from the Column grid column, in the drop-down list of the Property grid column. Repeat this step to set mapping for other table columns, if needed.

Images_mapping_details_column

4.If you don't need to add a mapping condition, skip this and the following two steps. Otherwise, in the Conditions grid click <Add a Condition> and select the condition table column from the drop-down list.

Images_mapping_details_conditions

5.Click the corresponding cell in the Operator column and select the condition operator from the drop-down list.
6.Click the corresponding cell in the Value column and enter the needed value for condition.
7.If you need to map the entity to more than one table, repeat steps 2-6 for other tables.
8.Click OK.

Now the entity is mapped as required.

 

ExpandedToggleIcon        Deleting Column Mapping

To delete column mapping, in the Column Mappings grid of the Entity Mapping Details dialog box click the row and select (None) in the Property grid column.

 

ExpandedToggleIcon        Deleting Table Mapping

To delete table mapping, do the following:

1.Right-click the entity on the diagram and select Mapping Details from the popup menu.
2.In the Storage Entities grid click the table or view for deleting and choose <Delete> in the drop-down list.
3.Click OK.

 

ExpandedToggleIcon        Creating a QueryView Mapping

To create a QueryView mapping, do the following:

1.Right-click the entity on the diagram and select Mapping Details from the popup menu.
2.Switch to the Query View tab.
3.Type the Entity SQL query into the Query box, e.g. as follows:

Images_Query-View

Where:

oTestmodellerModel is the namespace for the context model;
oEmployeeWithDepartment is the name of the entity in the context model;
oTestmodellerEntitiesStoreContainer is the name of the storage model container;
oDepartments and Employees are entity sets of the table objects in the storage part;
oEmployeeID, LastName, etc. are table column names in the storage part.
4.Click OK.

Now mapping is set as required.

 

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.