Store Enums as Strings
CodeFluent Entities fully suports .NET enumerations since 2005. This supports includes:
- Being able to create your own enumerations at design time,
- Use already existing CLR enumerations.
- Using our designer, you can create and use enumerations in your model (e.g. OrderStatus in the screenshot below):
Currently CodeFluent Entities allows to store the enumeration value as a numeric value. Sometimes you prefer storing it as text so we write an aspect to do that.
After adding the Aspect, you’ll see new properties in the property grid:
The “Store Enumeration As Text” property exists at:
- Enumeration level
- Property level
You can also specified the column size. By default the column size will be computed from the enumeration values when possible. For example if you have a flag enumeration with values “First”, “Second”, “Third” the longest value will be “First, Second, Third”, so the column size will be 21. Of course you can override the value by setting the property “Default Column Size” at enumeration level or “Column Size” at property level.
How to install the aspect
Create a C# project in the solution and copy the Aspect files: https://github.com/SoftFluent/CodeFluent-Entities/blob/master/Extensions/SoftFluent.StoreEnumAsText/SoftFluent.Samples.StoreEnumAsText.Aspects/StoreEnumerationAsTextAspect.cs
Add a reference in the model to the aspect project:
Then, select those two projects:
Finally, add the Aspect into your model:
The R&D team.