Map Enum to Null when not matched by Name #14
Replies: 2 comments 5 replies
-
You can write that check inside a |
Beta Was this translation helpful? Give feedback.
5 replies
-
See issue: #4 (comment) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a nullable enum property on the source side and get this property with value 0 instead of NULL.
But 0 is not a represented value in the enum so AutoMapper with
ConvertUsingEnumMapping
throws an exception that the enum can not be mapped. Is there a way to map it toNULL
whenever the value is not represented in the source enum? Some way to prevent this runtime error?Mapping configuration:
Mapping:
Exception:
My current workaround is to apply this before the map:
Is there a better way? I can't use
ConvertUsingEnumMapping
when I make the enum types in the map nullable.The problem is that this can happen for every enum property so I'm at big risk of runtime errors atm because I have no control over the source side of the data.
Example repo: https://github.com/matthiaslischka/AutoMapperNullEnumIssue/blob/main/AutoMapperNullEnumIssue/UnitTest1.cs
Beta Was this translation helpful? Give feedback.
All reactions