I am updating or creating an entity that has a child relationship, say that the aggregated root is Product (ProductId, Title), which has zero or more ProductSuppliers (ProductSupplierId, SuppliedAtPrice, SupplierInfoId), and DTO is a similar structure (all information) . Simple enough.
I created a simple map for ProductDTO and ProductSupplierDTO, and it works, as I assume, for future objects.
However, when processing DTO, I can update an existing object, so I am doing something like this:
Product product = productService.GetViaProductId(productDTO.ProductId) ?? new Product();
productDTOMapper.Map(productDTO, product);
productService.Update(product);
For primitive types existing on a Product, its fine, like any ORM, will recognize if it is dirty or not. However, I don’t want Automapper to simply replace Product.Suppliers with a new set, I want to connect some logic somewhere to iterate over the product. Suppressors and check whether an entity exists and whether it updates, or create a new one, ProductSupplier is not a value object, it has an Id, ProductSupplierId.
I can not find where to connect this inside the display.
Any suggestions?
user53791
source
share