Entity Framework + AutoMapper ( Entity to DTO and DTO to Entity )

后端 未结 8 1248
逝去的感伤
逝去的感伤 2021-01-30 07:38

I\'ve got some problems using EF with AutoMapper. =/

for example :

I\'ve got 2 related entities ( Customers and Orders ) and they\'re DTO classes :

         


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 07:59

    You should ignore mapping of some entity properties like so:

    Mapper.CreateMap()
                    .ForMember(dest => dest.EntityKey, opt => opt.Ignore())
                    .ForMember(dest => dest.Licenses, opt => opt.Ignore())
                    .ForMember(dest => dest.AccessCodes, opt => opt.Ignore());
    

    If you examine the message from the exception thrown by Automapper, you should see the entity properties that cannot be mapped and ignore them as above.

提交回复
热议问题