Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: EF 6 - Can an option be set to store Enums as Strings?

$
0
0
Yes you can do it, but its hackery. I used the same hackery on EF4 to be able to use enums, though i stored as int (somewhat easier).
public enum Quantity : int
    {
        None = 0,
        Few = 1 << 0,
        Some = 1 << 1,
        Bunch = 1 << 2
    }

    public class SomeClass
    {
        protected internal string AppleQuantity { get; set; }
        [NotMapped]
        public Quantity Apples
        {
            get
            {
                var val = (Quantity)Enum.Parse(typeof(Quantity), AppleQuantity);
                return val;
            }
            set
            {
                AppleQuantity = value.ToString();
            }
        }
    }

Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>