Entity Framework Feature Suggestions

Simple type mapping or mapped 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.

2,156 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Ladislav MrnkaLadislav Mrnka shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
    Adam RobinsonAdam Robinson shared a merged idea: Support char-valued enums  ·   · 
    AaronWAaronW shared a merged idea: Conversion lambdas as part of field/column mapping  ·   · 
    james.crowleyjames.crowley shared a merged idea: Support custom types / serialization  ·   · 
    planned  ·  Diego VegaAdminDiego Vega (Development Lead, DataFx) responded  · 

    UPDATE: We do plan to implement type conversions in the EF7 codebase. We are just not committed yet to doing it for the initial RTM and we are not actively working on it.

    Reverting status from “under review” to “no status” since we aren’t currently working on this. We will still consider it for future releases.

    52 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Dan MDan M commented  ·   ·  Flag as inappropriate

        "Planned" makes *much* more sense than "no status" (and is a huge relief). Thank you for clarifying!

      • Rowan MillerAdminRowan Miller (Admin, DataFx) commented  ·   ·  Flag as inappropriate

        Just to add some clarification around the recent change back to "no status".

        Type conversion is something that we do plan to implement on the EF7 code base, and we're building out the architecture with this (and many other improvements) in mind. We're just changing the status to reflect that we aren't actively implementing this feature at the moment.

      • Dan MDan M commented  ·   ·  Flag as inappropriate

        I'm completely gobsmacked. This is the fourth highest rated feature request on the list. We have been waiting for this for *years*. And now you are downgrading it to "no status"? It's not like "under review" was all that strong of a statement to begin with, but it least it was something. At the very least, could you communicate why this feature is not worthy of implementing in the very near future? Clearly, a lot of people are very anxious to have it. Thanks.

      • Frank QuednauFrank Quednau commented  ·   ·  Flag as inappropriate

        I am surprised that such a useful and important feature that doesn't seem desperately complicated doesn't get a higher priority.

      • AndrewAndrew commented  ·   ·  Flag as inappropriate

        I hate stumbling upon limitations like this at the end of a project! I could really use this feature for a pure model containing just CultureInfo and simple scaffolding of string inputs that convert easily.

      • Alex PasternakAlex Pasternak commented  ·   ·  Flag as inappropriate

        Absolutely, please please add this feature. Enums as strings would be of immediate use, as would mapping between datetime and datetimeoffset in db/object as necessary.

      • MachetMachet commented  ·   ·  Flag as inappropriate

        I need to map my nodatime classes to database somehow... this feature would be great. Also in complex domains there is often need to map value objects to database. IMO this feature is must have in EF

      • Matt JohnsonMatt Johnson commented  ·   ·  Flag as inappropriate

        "Under Review" since Dec 11 2012 - over a year? I dug through the EF issues on codeplex and couldn't locate anything related. Is this really under review?

      • Caspian CanuckCaspian Canuck commented  ·   ·  Flag as inappropriate

        A truly useful feature would be the ability to define lambda expressions for property-level conversions in the EF context configuration, which would help address the enums-as-strings problem and a bunch of others.

        Example:

        public enum MyEnum { One, Two, Three }

        public class MyClass
        {
        public MyEnum MyEnumProperty { get; set; }
        }

        public class MyClassConfig : EntityTypeConfiguration<MyClass>
        {
        public MyClassConfig()
        {
        this.Poperty(p => p.MyEnumProperty)
        .HasColumnType("varchar")
        .Value(enum => return Enum.GetName(typeof(MyEnum), enum));
        }
        }

      • JeremyJeremy commented  ·   ·  Flag as inappropriate

        Enum as string is the reason I voted, but being able to integrate with libraries like nodatime would be zamazing!

      • Nathan DavisNathan Davis commented  ·   ·  Flag as inappropriate

        The lack of this feature is also annoying, because while Sql Server supports a "plain old date", the .NET Framework does not. The lack of type conversion means that I can't even create my own "plain old date" and map it.

      ← Previous 1 3

      Feedback and Knowledge Base