Enum and Flags support in ormlite servicestack

Due to my error message:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code Additional information: Conversion failed when converting the nvarchar value 'AB' to data type int. 

I have an enumeration with an AB value, and I want to save it as an integer, not an nvarchar value. I have an enumeration with flag attributes: [Flags]

 public enum VisibleDayOfWeek : int { None = 0, Monday = 1, Tuesday = 2, Wednesday = 4, Thursday = 8, Friday = 16, Saturday = 32, Sunday = 64 } 

I cannot save several days in db, but I can save the sum of flag values ​​that represent several days.

I do not want to create an integer wrapper around these enumeration properties.

The main type of enumeration is a byte or an integer, so why is it stored as a string / varchar? It's pointless. Even the entity infrastructure has correctly handled enum support over the years ...

What is the solution in this case?

This guy seems to have the same problem: https://github.com/tapmantwo/enumflags

+7
servicestack ormlite-servicestack
source share
2 answers
+4
source share

As far as I know, ormlite version 3 does not support enumeration, who knows about the next version. any way your solution is to just use an integer shell

 public int VisibleDayOfWeek { get; set; } [Ignored] public VisibleDayOfWeek VisibleDayOfWeekEnum { get { return (VisibleDayOfWeek)VisibleDayOfWeek; } set { VisibleDayOfWeek = (int)value; } } 

Even the framework structure has correctly dealt with enum support over the years

the entity infrastructure has enumeration support after version> 4, also you should not expect that the significant structure of an entity is rich if ormlite is just like its name "lite".

+5
source share

All Articles