I have a .Net 4.6.1 project using Automapper 9.0.0 and the following simple test code:
private MyObj Update(MyInputModel inputModel)
{
Dictionary<string, object> blah = new Dictionary<string, object>();
blah.Add("TypeId", 29);
var targetObject = RetrieveObjectFromSession<MyObj>(inputModel.Guid);
var config = new AutoMapper.MapperConfiguration(cfg => cfg.CreateMap<Dictionary<string, object>, MyObj>());
var mapper = new AutoMapper.Mapper(config);
mapper.Map(blah, targetObject);
return targetObject;
}
The MyObj
object has a property on it called TypeId
and I've made sure the casing is correct but Automapper just will not update the targetObject
with the passed in Dictionary. As far as I can tell from the Automapper documentation, this should be possible.
docs.automapper.org/en/latest/…
如此处stackoverflow.com/a/57732789/3797799所示,我认为您在实例化 时必须传递一个空配置对象MapperConfiguration,例如new MapperConfiguration(cfg => { }). 这让 Automapper 隐式地完成这项工作。