views:

85

answers:

2

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
}
A: 

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
mmacaulay
This wont work, I am trying to access the built in MySQL privilege tables. THerefore i cannot change/create schema/column definition.
LnDCobra
Ah I see, sorry, can't help you then :(
mmacaulay
+2  A: 

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.

Jamie Ide
Thanks for that :D I found from that post that YesNoType is actually built into NHibernate (At least the version I'm using 2.x)
LnDCobra