Skip to content

Mapping Graphs

Leonardo Porro edited this page Jan 12, 2023 · 36 revisions

Mapper takes a source graph and copies the values recursively into a target entity graph, using the current configuration.

For the EntityFramework extension, source graph is passed as an argument by the user, then Key members are mapped and a query by key is executed to load the target entity graph. The query includes Aggregations up to the first level, and all Compositions recursively.

Then the graph is traversed (depth-first) to map the values.

Primitive values are copied as-is or with some type conversion (e.g.: string to int). If there is any difference between source and target primitives, the entity state is set to Modified, otherwise, is set to Unchanged.

In the case of Aggregations only the Key members are mapped, and the rest of values are ignored, the entity state is set to Unchanged, because it is supposed that independent entities should exist before the current entity is saved.

For Compositions a merge by Key is performed. If the dto exists in source but not in target, the entity is created and the entity state is set to Add. If the dto and entity exist in both, source and target, its members are mapped, and the entity state is set to Modified. Finally if the entity exists in target only, its state is set to Delete.

Diagram