a.Metadata Mapping Pattern

  1. Motivation

      1. Holds details of object-relational mapping in metadata in-order to create loosely coupled Mappers

  2. Summary

      1. A Metadata Mapping allows developers to define the mappings in a simple tabular form, which can then be processed by generic code to carry out the details of reading, inserting, and updating the data.

      2. Mapping can be implemented in two ways code generation and reflective programming.

      3. Code generation is a less dynamic approach since any changes to the mapping require recompiling and redeploying at least that part of the software.

      4. With a reflective approach, you can just change the mapping data file and the existing classes will use the new metadata.

      5. On most occasions you keep the metadata in a separate file format. These days XML is a popular choice as it provides hierarchic structuring while freeing you from writing your own parsers and other tools.

      6. Metadata Mapping can interfere with refactoring, particularly if you're using automated tools but On the other hand, Metadata Mapping can make refactoring the database easier,

            1. A typical metadata mapping pattern

            1. Metadata mapping using Entity framework

  1. When to Use

      1. When implementing ORM based solution.

    1. Usually we don`t need to handcraft this solution because most of popular ORM solution like Entity Framework (EF) support it out of the box.

  1. References