Enum in Linq Queries #2475
Replies: 3 comments
-
What's your custom serializer? That's the most likely culprit |
Beta Was this translation helpful? Give feedback.
-
We implemented a custom serializer from ISerializer. It seems that the serializer is not used when generating the queries. It is only used when serializing docs for saving or deserializing the query results. I have tried putting a breakpoint on all methods but they don't get hit unless there are results from the repository. All the other queries work without any issues. I just cannot overwrite the Enum values to query using camelcase values. Is there any specific method I could try to override for query generation? I was able to find a workaround using MatchesSQL but was hoping there is a better way |
Beta Was this translation helpful? Give feedback.
-
@darena-pjindal Don't use a custom serializer is the only real answer here. The Linq support has to "know" how to match the casing and structure of the Json data, and it can't know that from any kind of custom serializer. I'm converting this to a discussion as I don't think this is actually an error with Marten itself. |
Beta Was this translation helpful? Give feedback.
-
I am new to Marten and trying to understand how the enum queries work. I have an object that has an enum Gender with values of Male, Female and Unknown. I am using a custom serializer with EnumStorage as string and casing as camel. The value for gender gets stored as male/female/unknown (lower case). Now, I am trying to make a query in linq where p.Gender=Gender.Male. The query that is generated has the parameter value as Male (upper case) and thus fails to find any results. Am I doing something wrong or is there a setting that I might be missing. I am using a custom JsonSerializer but don't have any other issues except with this enum search.
Beta Was this translation helpful? Give feedback.
All reactions