- Notifications
You must be signed in to change notification settings - Fork 389
Closed
Description
Hello everyone !
We are facing an issue (or a bad use of the lib) with Mapster 3.3.2.
We are trying to map two models by using this code :
public Update(MyModel myModel) { // We force here the mapping with values and not with properties TypeAdapterConfig<SubModel, MyEntity> .NewConfig() .Map(dest => dest.Id, src => myModel.Id) .Map(dest => dest.Label, src => myModel.Label); // SubModels are of course an IEnumerable of SubModel type myRepository.Update(profilDroit.SubModels.Adapt<IEnumerable<MyEntity>>()); }The issue with the code above is each time we call Update(myModel) method, we get SubModels received the first call values of myModel,
To be clearer a bit of code :
MyModel myModel1 = new MyModel { Id = 1, Label = "Label 1" }; Update(myModel1); // Calling the previous method described above // all SubModels got 1 as Id and "Label 1" as Label MyModel myModel1 = new MyModel { Id = 2, Label = "Label 2" }; Update(myModel1); // Calling the previous method described above // all SubModels also got 1 as Id and "Label 1" as Label instead of 2 and "Label 2"However if we use this implementation :
public Update(MyModel myModel) { var config = new TypeAdapterConfig(); config.NewConfig<SubModel, MyEntity>() .Map(dest => dest.Id, src => myModel.Id) .Map(dest => dest.Label, src => myModel.Label); myRepository.Update(myModel.SubModels.Adapt<IEnumerable<MyEntity>>(config)); }This works perfectly.
So why, when using static TypeAdapterConfig, the previous value mapping for a NewConfig is not replaced by the new one ?
(By the way, we read the source code and saw that NewConfig do a Remove of the config then a ForType, so it would had to do the job normally...)
Thank you in advance. :)
Metadata
Metadata
Assignees
Labels
No labels