Custom type mapping and type conversion support
Currently the only conversion available in EF Core libraries 4.5 and EF 5.0 are enums mapped to integers but that is only tip of the iceberg. There is whole big feature behind - simple type mapping or conversions defined directly in mapping.
For example what if my database contains char column with Y, N values and I want to map it to bool property directly without any additional stuff doing the conversion inside my entity? Or more complex example - what if my column contains value like en-us and I want to map it to instance of CultureInfo? There are so many examples which can fit into this feature ...
Feature like enum mapping scales EF mapping features by inches. Ability to define custom conversion or simple type mapping scales EF mapping features by miles.
The feature is part of EF Core 2.1, which is currently in preview. Please create issues in our issue tracker if you find any problems.
@Tyson, we don't intend to build any more features of this magnitude into EF6. We would rather spent the effort of the team on improving EF Core (yes, to continue closing the functionality gap, among other goals). In theory, if someone from the community decided to contribute something like this for EF6, they could try, but the extensive work on validating the feature and the risk for the redesign makes it very unlikely.
Umm... did this get moved from EF6 to EFCore?
What about this feature for EF6?
Given EFCore is still no where near feature parity with EF6 we can not migrate to EFCore, so we are still desperately waiting for this feature in EF6...
5 years after request submitted. perfect!
@Diego Vega Could you please provide estimate when it will be done? Thanks
i think management on project is not good and prioritization also.
Just found better alternative for EF with alll I need but without automigrations https://servicestack.net/ormlite. I spent so much time on EF but now can't wait more.
Guys, it is really important feature. Please implement it. Or We will celebrate 4 years in February?
Mikkel Lund commented
Is this coming to EF6? We really need an easy way to work with NodaTime in legacy databases.
@Dirk Watkins: enums mapped to a table would not be part of the *simple* type mappings and type conversions feature we have planned. Consider voting for https://data.uservoice.com/admin/forums/72025-entity-framework-feature-suggestions/suggestions/2683498.
Dirk Watkins commented
Enum to a lookup DB table please, with a nice display name column based on the Description attribute.
Arh, finally some light at the end of the tunnel! NodaTime will be much easier to use. TimeSpan >24h duration can be solved. Proper domain models can be based directly on entity classes without sacrificing clarity. Custom value types can be used directly in entity classes. The world will be a better place when issue 242 finally gets resolved :)
@Diego any updates? As @Dan mentioned I'd also would be happy to have this as a build-in feature.
Dan M commented
@Diego Vega, can you update us on the progress of this? We've passed the 4-year anniversary of this request, which is now the 3rd most popular on UserVoice. Not having this feature is causing a lot of pain. I hope this has finally become a priority for your team. Thank you!
Aron Tsang commented
I hope you reconsider your stance on this feature. As it stands OData4/EF is broken. The OData team are pushing for usage of Microsoft.OData.Edm.Library.Date (whilst dropping support for DateTime) whilst your team are quite frankly refusing to support deserialization of DbDate to anything except DateTime.
It seems like your two teams are giving conflicting response, when the OData project lives and dies on EF support.
Paul Lee commented
I just can not understand, this should be a quick and easy update to EF and yet 4 years has passed and this is still not being selected for development.
A clear explanations to why this is such a mission impossible for the development team is also missing.
Matt Johnson commented
FYI - I think this is being tracked here: https://github.com/aspnet/EntityFramework/issues/242
Mark Junker commented
I'd really like to see a full featured type conversion API like the one from NHibernate which is just done right.
Nathan Alden, Sr. commented
A feature to map enums to and from strings in the database is very important when dealing with PostgreSQL custom enum types, which may be represented as strings.
Zackary Geers commented
This is a major feature for several database designs I've worked with, I'd really love to see this back in the queue. It will provide a lot more flexibility in working with legacy databases, and improve the ability to transition from other products onto EF.
Terrible, absolutely terrible, that an enterprise engine like entity framework doesn't support basic unsigned data types. Just awful, pathetic.