There are two types:
1) DTO type:
[DataContract]
public sealed class OrderDetailDto
{
[DataMember]
public Guid MergeId { get; set; }
[DataMember]
public int Id { get; set; }
[DataMember]
public string PostionName { get; set; }
[DataMember]
public decimal Quantity { get; set; }
[DataMember]
public byte[] Version { get; set; }
}
2) corresponding domain type:
public sealed class OrderDetail
{
public Guid MergeId { get; set; }
public int Id { get; set; }
public string PostionName { get; set; }
public decimal Quantity { get; set; }
public byte[] Version { get; set; }
}
and two collections: Collection<OrderDetail>
and Collection<OrderDetailDto>
.
Collection<OrderDetailDto>
has data changes, that was made somewhere. Now I want to apply these changes to Collection<OrderDetail>
, using Automapper.
For simplicity, let's think, that items count in these collections are equal, but the order of items may differ.
To map collection items correctly, I want to use MergeId
property. I need something like this:
Mapper.CreateMap<Collection<OrderDetailDto>, Collection<OrderDetail>>()
.MappingExpression((dto, do) => dto.MergeId == do.MergeId);
Is this possible to do with Automapper?