R – Nhibernate Enum Error

enumsnhibernate

This is a bug?
Using NHibernate.Expression.Example.Create(userExample) if my class use Int32 on property 'Type' all works fine.

public class User:Person
{

    public virtual String NickName { get; set; }
    public virtual String Password { get; set; }
    public virtual Int32 Type { get; set; }

    public enum UserType
    { 
        Normal = 0,
        Broker = 1
    }

}

but using the enum the critéria return null:

public class User:Person
{
public virtual String NickName { get; set; }
public virtual String Password { get; set; }
public virtual UserType Type { get; set; }

public enum UserType
{ 
    Normal = 0,
    Broker = 1
}

}

In console, query is showing 'Broker', this is the problem, i think that is a error of NHibernate, any sugestions?

Best Answer

Without seeing your query, you can try this expression. I assume your storing the enum as an int your db.

 Expression.Eq("Type",(int) userType);