-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enums Stored as Strings #1381
Comments
The default will still be to store the underlying type of the enum. Swapping to use the string will be covered by #242 |
Is there any workaround to make it work with we have for now (RC1 or RC2)? |
You could do the conversion in code in the entity and map the underlying string property using EF (you can make the property private and still map it) and leave the enum property unmapped (e.g. with |
That is exactly what i thought. Thanks! |
Worked fine for me. Thank you divega. |
How about LINQ? I say about something like
I know, I can use Mapped string and NotMapped Enum, but it's realy ugly with linq. I actualy want to see strings in equation and in DB for many reasons |
@DantaliaN00 server-side querying based on equality should be enabled for the majority of mappings by the type conversion feature described in #242. We will start working on that feature soon, although we are planning to ship it after 1.1. |
Part of issues #242 and #1381 Instead of using special code for materialization and parameter creation, type mappings now add an appropriate type converter for enum types that converts two and from the underlying numeric value. (Special code is still present for providers that are not updated and do not create mappings with converters.) This means that if the column is instead a string column, then a different converter can be used which converts to and from the string values of the enum. SQL Server and most other providers will get this for free when updating to 2.0 and adding support for value conversions. SQLite is the exception since it has weird type mapping.
Part of issues #242 and #1381 Instead of using special code for materialization and parameter creation, type mappings now add an appropriate type converter for enum types that converts two and from the underlying numeric value. (Special code is still present for providers that are not updated and do not create mappings with converters.) This means that if the column is instead a string column, then a different converter can be used which converts to and from the string values of the enum. SQL Server and most other providers will get this for free when updating to 2.0 and adding support for value conversions. SQLite is the exception since it has weird type mapping.
In 2.1, mapping an enum property to a string property will result in the enums being saved as strings in the database. |
@ajcvickers, any chance that native database enums could be supported as well (i.e. #3620)? This would be great for PostgreSQL. |
@roji Yes, but there are some more changes needed that have not yet been completed. They should be done relatively soon (depending on how much time I get to write code). The general idea is that:
|
@ajcvickers wonderful, I'll be looking forward to implementing PostgreSQL support for this! One quick question: if the user wants to override and store the enum as a number or string regardless of what the type mapper says, they'll still be able to do so via a value converter, right? |
@roji Yep. |
Will EF7 have optional (or default) support for storing the enum string values instead of the numeric values in the database?
The text was updated successfully, but these errors were encountered: