Closed luczito closed 1 month ago
I also encountered it. The Id of my parent class is int, and the subclass uses new to modify the guid, and a type conversion error is reported.
---> Mapster.CompileException: Error while compiling
source=System.Nullable`1[System.Guid]
destination=System.Int32
type=Map
Even if I configure ignore, I still get an error
config.ForType<EditUserModel, User>()
.IgnoreIf((model, user) => model.Id == null, a => a.Id)
.IgnoreNullValues(true);
I fixed this by overwriting the value with an aftermapping statement in my mapping configs. Don't know if that can help you @coolqingcheng
config.NewConfig<DtoDerived, DomDerived>()
.TwoWays()
.AfterMapping((dto, dom) => dom.Payment = dto.Payment.Adapt<DomDerivedPayment>());
I have the following classes and patterns that Mapster can't work with. Specifically the pattern for overwriting the DerivedPayment in each of the derived classes. When debugging it shows that the "setter" gets the correct value, Dom/DtoDerivedPayment. But when the "getter" is called this value is somehow overwritten to the base instance of Dom/DtoPayment instead, resulting in a "System.InvalidCastException : Unable to cast object of type 'DomPayment' to type 'DomDerivedPayment'."