Automapper creating new instance rather than map properties

后端 未结 3 576
不思量自难忘°
不思量自难忘° 2020-12-15 21:05

This is a long one.

So, I have a model and a viewmodel that I\'m updating from an AJAX request. Web API controller receives the viewmodel, which I then update the ex

3条回答
  •  一向
    一向 (楼主)
    2020-12-15 21:49

    According to the AutoMapper source file that handles all ICollection (among other things) and the ICollection Mapper:

    The collection is cleared by a call to Clear() then added again, so as far as I can see there is no way that AutoMapper will be able to automagically do the mapping this time.

    I would implement some logic to loop over the collections and AutoMapper.Map the ones that are the same

提交回复
热议问题