开发者

NHibernate MySQL Enum

开发者 https://www.devze.com 2022-12-27 18:30 出处:网络
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# Boolea

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号