You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes a property in a ViewModel is a record, for example: public record PeriodData(DateOnly StartDate, DateOnly EndDate);
When at least one property of the record changes, I need the record instance to be replaced. However, at the moment the mapper seems to mutate the existing record instead, and as a result the UI does not update.
I initially thought that using .ForMember(dest => dest.ValidPeriod, opt => opt.MapFrom(src => new PeriodData(src.ValidPeriod.StartDate, src.ValidPeriod.EndDate)));
or .ForMember(dest => dest.ValidPeriod, opt => opt.MapFrom((src, _, _, context) => context.Mapper.Map<PeriodData>(src.ValidPeriod)));
would solve this problem, but it does not.
Would it make sense to have a mapping option for record types that explicitly prevents mutation and always creates a new instance instead?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Sometimes a property in a ViewModel is a record, for example:
public record PeriodData(DateOnly StartDate, DateOnly EndDate);When at least one property of the record changes, I need the record instance to be replaced. However, at the moment the mapper seems to mutate the existing record instead, and as a result the UI does not update.
I initially thought that using
.ForMember(dest => dest.ValidPeriod, opt => opt.MapFrom(src => new PeriodData(src.ValidPeriod.StartDate, src.ValidPeriod.EndDate)));or
.ForMember(dest => dest.ValidPeriod, opt => opt.MapFrom((src, _, _, context) => context.Mapper.Map<PeriodData>(src.ValidPeriod)));would solve this problem, but it does not.
Would it make sense to have a mapping option for record types that explicitly prevents mutation and always creates a new instance instead?
All reactions