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

后端 未结 8 1376
逝去的感伤
逝去的感伤 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 08:20

    Your problem is because Automapper loses the EntityKey associated with the record. As the EntityFramework does not by default handle POCO's (Plain Old CLR Object)

    Jay Zimmerman has a good example here of how to handle this from is. gd /4NIcj Also from Jaroslaw Kowalski (part of the EF team I believe ) has this example for using POCO's within EF, which may translate well to use with Automapper (I've not yet had a chance to try it) : http://blogs.msdn.com/jkowalski/archive/2008/09/09/persistence-ignorance-poco-adapter-for-entity-framework-v1.aspx

提交回复
热议问题