I'm using asnet boilerplaite aspnet core and ef core. I've initialized automapper.collection in PreInitialize as follows:
Configuration.Modules.AbpAutoMapper().Configurators.Add(
cfg =>{
cfg.AddCollectionMappers();
cfg.CreateMap<OrderDTO, Order>().EqualityComparison((odto, o) => odto.ID == o.ID);
cfg.CreateMap<OrderItemDTO, OrderItem>().EqualityComparison((odto, o) => odto.ID == o.ID);
}
);
I'm using ObjectMapper.Map(odto, o); to map between the dto and entity, but what I find are new orderitem in the orderitems collection within orders save fine, but any edits to existing entries seem to not update to the db.
The order entity and collection are loaded from the repository using the following:
var @item = await _orderRepository.GetAll().Include(x => x.Items).Include(x => x.Items).ThenInclude(x => x.Product).AsNoTracking().FirstOrDefaultAsync(x => x.Id == id);
here is the Update method:
public override async Task<OrderDto> Update(OrderDto input)
{
var ord = await _orderManager.GetA(input.Id);
ObjectMapper.Map(input, ord);
CheckErrors(await _orderManager.UpdateA(ord));
return MapToEntityDto(await _orderManager.GetA(input.Id));
}
The values of input and ord variables are as follows when trying to update the orderitem record:
input {OrderDto}
Code "1" string
Id 1 int
Items Count = 1 System.Collections.Generic.ICollection<OrderItemDto>
- [0] {OrderItemDto}
Id 1 int
OrderId 1 int
+ Product {ProductLoadDto}
ProductId 4 int
Quantity 22 double
MovementDate {28-Jul-18 2:36:41 AM} System.DateTime
ord {[Order 1]} Order
Code "1" string
Id 1 int
Items Count = 1 System.Collections.Generic.ICollection<OrderItem>
- [0] {OrderItem 1}
Id 1 int
OrderId 1 int
+ Product {[Product 4]} Venues.Products.Product
ProductId 4 int
Quantity 1 double
MovementDate {28-Jul-18 12:06:41 PM} System.DateTime
Is there something I'm missing to get automapper.collection to handle the collection edits automatically ?
Have you tried the Entity Framework Core repo?
https://github.com/AutoMapper/AutoMapper.Collection.EFCore/tree/development