-
Notifications
You must be signed in to change notification settings - Fork 2
Home
busterwood edited this page Mar 5, 2017
·
2 revisions
One of the most common activities of software development is mapping (converting) between different representations of the same thing. Existing libraries tend to be specific to a domain, for example:
- Automapper can be used to map between objects
- EntityFramework can be used to map between database and objects.
There are two common approaches to mapping:
- Configuration, be that in code, metadata attributes or external files;
- Convention, i.e. the name of things must match.
I think that in many cases a rules based mapping is more applicable, i.e.
- Try a case insensitive match - as humans we don't distinguish words of different case as different, but computers tend too
- Remove underscores and try to match
- Remove repeating words and try to match, e.g. when mapping from ORDER_ID database column to an Order class then try mapping to ID.
What about all the edge cases, I believe the above rules will get all mappings 95% correct, so what about the other 5%? Rather than trying to define all possible rules I prefer to allow custom mapping code to be injected to handle the edge cases.