Replies: 1 comment 8 replies
-
Hello @joaooo Do you want to map Enum to Class ? |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, i'm currently migrating from AutoMapper to Mapster but i'm having some issues with a few things and i was wondering if there wasn't a different way to solve this.
Consider this following example:
I want to map my ProductDTO.Model from Product.ModelId, in AutoMapper i used to do this:
.Map(d => d.Model, source => Enum.GetName(typeof(Enums.Model), source.ModelId))
but when i tried this in Mapster, i get the error "System.InvalidOperationException: Cannot convert immutable type, please consider using 'MapWith' method to create mapping", so i tried to change my code to use .MapWith and returned my DTO but still had the same error, then i realized the error was coming from trying to map my DB Model to the Enum itself and i added this attribute to my Model class: [AdaptIgnore(MemberSide.Source)] and it fixed the error.
I was wondering if there is a different way to accomplish this without having to change my DB Models since i have quite a few of them. I tried to look for workarrounds with .Ignore but i could only ignore the destination class and not the origin.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions