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 (将#修改为@)