Should the EnumDataTypeAttribute work correctly in .NET 4.0 using Entity Framework?

后端 未结 1 1097
清歌不尽
清歌不尽 2021-01-06 23:47

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.

I have read some article

1条回答
  •  一整个雨季
    2021-01-07 00:34

    This is because of design flaw in .NET framework. .NET framework contains famous System.ComponentModel.DataAnnotations namespace where multiple different attributes are defined. Many different parts of .NET framework are using this namespace but they are using it to achieve different tasks and every such part use only some subset of attributes. This causes a lot of confusion.

    EnumDataTypeAttribute is such example. This attribute is only for ASP.NET Dynamic Data. It allows you to mark int property with this attribute and automatically generated UI will show drop down with enum values instead of textbox for numeric values. So there is mapping from enum to int but it is in UI layer not in model / persistence layer.

    0 讨论(0)
提交回复
热议问题