3

I am just getting into EF. For the past 2 years I have been coding database code by hand and finally got fed up with it. I am having one issue when it comes to using enums with E.F. All my previously coded enums used display attributes so that when bound in xaml to a data form or any other control, would display friendly names instead of code names. EX display "Light Brown" instead of "LightBrown or light_brown" etc. All the enum designer allows is to set values and names. Is there a way to get these auto enums to show a different name when bound to?

[Display(Name="Light Brown")]
Light_Brown,

Edit I am not looking how to convert enum names into friendlier names. I already know how to do that. My issues is accessing the auto generated code for enumerations that are automatically generated using the entity framework designer. It seems there is a way to reference an external code file so I am going to look into this.

Adrian
  • 3,332
  • 5
  • 34
  • 52

2 Answers2

3

Found a question and answer here on stack. You can circumvent this issue by using the "Reference External Type" option in the designer. This is only a solution in the event you are using the database first design of Entity Framework and not the model first design.

Entity Framework 5 Enums with Description attribute using Database First

The author answered his own question under the comments of his question.

Community
  • 1
  • 1
Adrian
  • 3,332
  • 5
  • 34
  • 52
2

Try using

[Description("Light Brown")]
Light_Brown,

Check out this answer you might need to add a converter.

Community
  • 1
  • 1
sergioadh
  • 1,461
  • 1
  • 16
  • 24