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.

1,858 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  ·   · 

    44 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...
      • 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.

      • Nathan DavisNathan Davis commented  ·   ·  Flag as inappropriate

        Another case is when mapping custom types, such as those used in http://nodatime.org/. The concept of "primitives" should really be more than the .NET primitives in terms of Domain Driven Design and the ORM mapping.

      • Yves SchelpeYves Schelpe commented  ·   ·  Flag as inappropriate

        I really hope this will get there in the next release!
        It would greatly improve the programming experience & readability

      • Simon .T.S.Simon .T.S. commented  ·   ·  Flag as inappropriate

        Can't believe after all this time there's still no type conversion. Back to NH, nothing to see here!

      • Ahmed AlejoAhmed Alejo commented  ·   ·  Flag as inappropriate

        Working with EF intensively recently, got me to the need for this feature. I guess anyone starting to use EF in a real/big project will certainly end up with this need.

      • RJ HollbergRJ Hollberg commented  ·   ·  Flag as inappropriate

        We really just need mapping in general, preferably using lambda expressions. The types that are usable by ORMs and DBs in general are simply much more limited than a smart domain model requires. We have custom Money and Currency types that we need to map to numeric fields; we have a custom EmailAddress type that we want to map to string fields; We have Doubles that Oracle returns as type Decimal and we need to cast them back. Booleans and Enums are also prevalent in our model, as are Nullable<T> types.

      ← Previous 1 3

      Feedback and Knowledge Base