title: Should the EnumDataTypeAttribute work correctly in .NET 4.0 using Entity Framework?
body: <p>I have an enumeration which I'd like to persist as a value of some sort into the underlying database so that I can bring it back and forth.</p>
  
  <p>I have read some articles that suggest to create a enumeration wrapper with static implicit operators defined, mapped using a ComplexType object mapping as described in the link below.</p>
  
  <p><a href="http://blogs.msdn.com/b/alexj/archive/2009/06/05/tip-23-how-to-fake-enums-in-ef-4.aspx" rel="nofollow">How to fake Enums in EF4</a></p>
  
  <p>This solution works flawlessly! My thanks to <a href="http://blogs.msdn.com/b/alexj/about.aspx" rel="nofollow">Alex James</a>.</p>
  
  <p>Aside, I discovered of the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.enumdatatypeattribute.aspx" rel="nofollow"><code>EnumDataTypeAttribute Class</code></a> which purpose seems to handle enums persistence through Entity Framework. I tried it and it doesn't seem to work at all. Here's a code sample.</p>
  
  <pre><code>public enum StreetDirection {
      East
      , None
      , North
      , NorthEast
      , NorthWest
      , South
      , SouthEast
      , SouthWest
      , West
  }
  
  public enum StreetType {
      Avenue
      , Boulevard
      , Court
      , Crescent
      , Drive
      , Hill
      , None
      , Road
      , Street
  }
  
  public class StreetTypeWrapper {
      public int Value {
          get {
              return (int)t;
          } 
          set {
              t = (StreetType)value;
          }
      }
      public StreetType EnumValue {
          get {
              return t;
          } 
          set {
              t = value;
          }
      }
  
      public static implicit operator int(StreetTypeWrapper w) {
          return w.Value;
      }
  
      public static implicit operator StreetType(StreetTypeWrapper w) {
          return w == null ? StreetType.None : w.EnumValue;
      }
  
      public static implicit operator StreetTypeWrapper(int i) {
          return new StreetTypeWrapper() { Value = i };
      }
  
      public static implicit operator StreetTypeWrapper(StreetType t) {
          return new StreetTypeWrapper() { EnumValue = t };
      }
  
      private StreetType t;
  }
  
  public class Street {
      [EnumDataType(typeof(StreetDirection))]
      public StreetDirection Direction { get; set; }
      public string Name { get; set; }
      public int StreetId { get; set; }
      public StreetTypeWrapper Type { get; set; }
  }
  
  public class StreetTypeMapping 
      : ComplexTypeConfiguration&lt;StreetTypeWrapper&gt; {
      public StreetTypeMapping() {
          Property(o =&gt; o.Value)
              .HasColumnName("StreetType");
      }
  }
  </code></pre>
  
  <p>Now, if I believe and/or understanding correctly what MSDN says about the <code>EnumDataTypeAttribute</code> class, the <code>Direction</code> property should get persisted into the database. Well, it doesn't! I can't find a reason for this, except that EF doesn't support enums persistence. As for the <code>StreetTypeWrapper</code> and its <code>StreetTypeMapping</code> class, it does work flawlessly.</p>
  
  <p><strong>Are there any clue why the EnumDataType shouldn't work as expected?</strong></p>