Closed elrhomariyounes closed 10 months ago
Appreciate your work on this!
Question: it looks like the enum must match exactly the enum in postgresql. It looks like some projects use different naming conventions for enums between postgres vs. c#. Should we add support for reading a value from a [MapTo("value")]
attribute or a [StringValue("value"]
attribute?
i.e. given a postgres enum of:
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
Should we support the c# enum as:
public enum Mood {
[MapTo("sad")]
Sad,
[MapTo("happy")]
Happy,
// ...
}
Thoughts?
Thank you for taking time to review.
Regarding the question of supporting different naming conventions for enums between PostgreSQL and C#, I have given this some thought and would like to share my perspectives on this matter:
To ensure the most straightforward and predictable behavior, it is reasonable to place the responsibility on the consumer to maintain matching enum names between PostgreSQL and C#. I think all package clients would expect enum values to map directly without any additional configuration.
I think also in some edge cases we need to make it clear in the documentation on how enums are handled.
The idea of adding an attribute to map the c# enum with PostgreSQL one we can implement it as a configuration options, enabling clients to specify custom mapping rules in next releases.
- To ensure the most straightforward and predictable behavior, it is reasonable to place the responsibility on the consumer to maintain matching enum names between PostgreSQL and C#. I think all package clients would expect enum values to map directly without any additional configuration.
That's fair and I agree. Good point!
Much appreciated @elrhomariyounes!
What kind of change does this PR introduce?
supabase-community/supabase-csharp#66 Fix this bug when trying to perform a Where using enums
What is the current behavior?
Not working. A workaround using the EnumMember attribute to get the value and use it with Filter method
What is the new behavior?
As described in the bug. Being able to use Enums in the where clause.