Using Automapper to update an existing Entity POCO

后端 未结 2 1708
無奈伤痛
無奈伤痛 2020-12-08 16:18

I am using EF4 DbContext to provide the model for an ASP.NET MVC app. I use ViewModels to provide data to the views and Automapper to perform the mapping between the EF POCO

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 16:55

    There seem to be two approaches to dealing with the EF proxy issue:

    1. Switch off ObjectContext.ContextOptions.ProxyCreationEnabled, either for the whole application (in EF Context constructor or EDMX), or for the query where you need to guarantee getting an actual Entity object rather than a proxy.
    2. Using an extension to Automapper, documented here: https://gist.github.com/935461.

    Note. The latter is commented with "Room for improvement. See: Automapper : mapping issue with inheritance and abstract base class on collections with Entity Framework 4 Proxy Pocos".

提交回复
热议问题