如何解决AutoMapper获取对象差异
我有以下映射
public class OrderResponseDto: IHasCustomMapping
{
private List<OrderCollectionDto> _collection = new List<OrderCollectionDto>();
public List<OrderCollectionDto> Collection
{
get => _collection;
set => SetField(ref _collection,value);
// SetField method should compare the property and add it to response if it not equal.
}
public void CreateMappings(Profile configuration)
{
if (configuration == null)
throw new ArgumentNullException(nameof(configuration));
configuration.CreateMap<Order,OrderResponseDto>()
.BeforeMap((src,dst) =>
{
dst.Clear();
});
}
}
我这样使用它:
var snapshot = _mapper.Map<OrderCollectionDto>(order);
await _context
.SaveChangesAsync(cancellationToken)
.ConfigureAwait(false);
return _mapper.Map(order,snapshot);
当我调用_mapper.Map(order,response)订单集合不等于快照集合时 在调用SetField方法之前的调试中,我看到该订单集合已写入属性。我该如何解决?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。