Repository pattern and mapping between domain models and Entity Framework

后端 未结 6 1175
后悔当初
后悔当初 2020-12-04 07:15

My repositories deal with and provide persistence for a rich domain model. I do not want to expose the anemic, Entity Framework data entity to my business layers, so I need

6条回答
  •  执笔经年
    2020-12-04 07:49

    Like previous posts have said. It's probably best to wait untill after the repositories to do actual mapping.. BUT I like working with auto-mapper. It provides a very easy way to map objects to other objects. For some separation of concerns, you can also define the mappings in a separate project. These mappings are also generic / type-based:

    1. You specify the base type in the mapping and define how it fills the destination type
    2. Where you need the mapping, you just call Mapper.Map(baseTypeObject, DestinationTypeObject)
    3. Automapper should handle the rest

    This could do the trick, if I understood your question correctly.

提交回复
热议问题