NHibernate MySQL Enum
I am trying to access the "MYSQL" database tables to create a GUI for adding users and privileges.
Doing this, I have run into my first NHibernate problem. How do i map MySQL Enum's to a C# Boolean? Or if not possible then to at least a 开发者_运维知识库Enum?
The database fields are delcared as
enum('N', 'Y')
These are all of the privilege fields in the database.
Now is there anyway of getting this into an enum or even better, boolean in C#/NHibernate?
Edit #1: In C# if I need to declare an enum it will be the following:
enum YesNoEnum
{
Yes,
No
}
You can use a bool in C# and map it to a char in MySQL using a custom IUserType implementation. This example is exactly what you're looking for.
I don't know about using MySQL's enum with NHibernate, but I do know that if you want to use a boolean field in C# and have it mapped to a MySQL database, you can do this:
MyDto.cs:
public bool IsAdmin {get;set;}
Column definition in the database:
`IsAdmin` TINYINT(1) NOT NULL DEFAULT 0
精彩评论