Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found this way of doing it and it works, it just isn't the Enum directly. You have to create a facade class that can implicitly be mapped back and forth. It works, but not as smooth as I would have liked.</p> <p><a href="http://daniel.wertheim.se/2010/06/09/dealing-with-enumerations-and-entity-framework-4-code-first/" rel="nofollow">http://daniel.wertheim.se/2010/06/09/dealing-with-enumerations-and-entity-framework-4-code-first/</a></p> <pre><code>public enum InterestTypes { [Description("Attraction - for sightseers and adventurers.")] Attraction = 1, [Description("Event - fun for everyone (limited time).")] Event = 2, [Description("Recreation - parks, hiking, movies...")] Recreation = 3, [Description("Restaurant - good eats.")] Restaurant = 4 } public class InterestType { private InterestType() : this(default(InterestTypes)) { } public InterestType(int value) { Value = value; } public InterestType(InterestTypes type) { Value = (int) type; } public int Value { get; private set; } public static implicit operator int(InterestType type) { return type.Value; } public static implicit operator InterestType(int value) { return new InterestType(value); } public static implicit operator InterestTypes(InterestType type) { return (InterestTypes) type.Value; } public static implicit operator InterestType(InterestTypes type) { return new InterestType(type); } } </code></pre> <p>In your DataContext you need the following in your OnModelCreating method.</p> <pre><code> protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.ComplexType&lt;InterestType&gt;() .Property(o =&gt; o.Value) .HasColumnName("Type"); } </code></pre> <p>This tells Entity Framework to map the int value to the value in the database. I guess you could also use strings if you wanted to store the values as strings in the database.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload