Well, as far as I know, NHibernate stores enums as a string only in db by default. I seem to know what the problem is. Wrong way to create a table.
if you use Nhibernate, use the build function to create tables instead of manually creating tables, and then you will see that your enum is stored as a string.
We make extensive use of enums in our application, and it is reasonable for us to store it as strings in db. The reasons are simple, if I add a new value to enum tom, then if the default values ββare not set, my code and my data are closely related, which I definitely would not want.
SimpleConfig.ExposeConfiguration(c => new SchemaExport(c).Create(false, true)).BuildConfiguration();
Also, instead of using char for your string, you can use varchar for this property.
After the update: Could you do some manipulations before storing them in the database? Thus, when you want to save new char enums, write a function that generates an int value for you and saves it in the correct form, and then saves it or if you want to make it simple, the function may have a switch case.
So, what you are doing, you do not have access to this property, which is extracted from db, instead you add a new property to the Status class, which is based on the logic for obtaining the corresponding enumeration.
Do you think this is a good idea?
Hope this helps.
Baz1nga
source share