NH 3.2 QueryOver with enums

208 views
Skip to first unread message

Nadav Ben-Gal

unread,
Aug 21, 2011, 9:41:31 AM8/21/11
to nhusers
Hey,
I just updated from NH 3.0 to NH 3.2. (downloaded from the site, not
nuget)
I'm developing in c# 3.5, working on a winforms project.
my database is mysql (5.1.42-community)
------
after the updated the following query ( or any other queryover with
involves enum):
Session.QueryOver<Entity>().Where(e => e.Type !=
Entity.EntityType.General).List();
throws the following exception:
Cannot interpret member from ConvertChecked(e.Type)
at
NHibernate.Impl.ExpressionProcessor.IsMemberExpression(Expression
expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl
\ExpressionProcessor.cs:line 346
at
NHibernate.Impl.ExpressionProcessor.FindMemberProjection(Expression
expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl
\ExpressionProcessor.cs:line 166
at
NHibernate.Impl.ExpressionProcessor.ProcessSimpleExpression(Expression
left, Expression right, ExpressionType nodeType) in d:\CSharp\NH\NH
\nhibernate\src\NHibernate\Impl\ExpressionProcessor.cs:line 414
at
NHibernate.Impl.ExpressionProcessor.ProcessSimpleExpression(BinaryExpression
be) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl
\ExpressionProcessor.cs:line 409
at
NHibernate.Impl.ExpressionProcessor.ProcessBinaryExpression(BinaryExpression
expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl
\ExpressionProcessor.cs:line 506
at NHibernate.Impl.ExpressionProcessor.ProcessExpression(Expression
expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl
\ExpressionProcessor.cs:line 580
at
NHibernate.Impl.ExpressionProcessor.ProcessLambdaExpression(LambdaExpression
expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl
\ExpressionProcessor.cs:line 587
at NHibernate.Impl.ExpressionProcessor.ProcessExpression[T]
(Expression`1 expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate
\Impl\ExpressionProcessor.cs:line 598
at NHibernate.Criterion.QueryOver`2.Add(Expression`1 expression) in
d:\CSharp\NH\NH\nhibernate\src\NHibernate\Criterion\QueryOver.cs:line
749
at NHibernate.Criterion.QueryOver`2.Where(Expression`1 expression)
in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Criterion
\QueryOver.cs:line 357
at
NHibernate.Criterion.QueryOver`2.NHibernate.IQueryOver<TRoot,TSubType>.Where(Expression`1
expression) in

the enum is:
public enum EntityType
{
v1 = 0,
v2 = 1,
....
General = 999
}

Property code:

public virtual EntityType Type
{
get { return type; }
set { type = value; }
}


the mapping for it is:
<property name="Type" column="ENT_TYPE"/>
the column is an integer in the database.

i saw a jira bug that was fixed (https://nhibernate.jira.com/browse/
NH-2712) and another on (https://nhibernate.jira.com/browse/NH-2763)
that isn't, but both says vb.net.
I tried marking that column as not-null (both mapping and updated the
db) but it didn't helped.

any ideas why it does not work and more important, what i need to do
in order to fix it?

Thanks,
Nadav

Nadav Ben-Gal

unread,
Aug 21, 2011, 11:20:02 AM8/21/11
to nhusers
I've searched in NH code, and found the root of the problem (i think)
in ExpressionProcessor class, you can find in few: "if
(unaryExpression.NodeType != ExpressionType.Convert)"
the problem is, the type is ConvertChecked and not Convert. i changed
the code from
if (unaryExpression.NodeType != ExpressionType.Convert)
to
if ((unaryExpression.NodeType != ExpressionType.Convert) &&
(unaryExpression.NodeType != ExpressionType.ConvertChecked))
lines: 173, 229, 305, 343
it did the job for me. and there isn't any hazard changing it as much
as i'm understanding (or is it and i'm missing something?).

I would like to hear what you think about it, and what i can do (more/
else...)

long live open-source :))

Thank,
Nadav
> NHibernate.Criterion.QueryOver`2.NHibernate.IQueryOver<TRoot,TSubType>.Wher e(Expression`1

Richard Brown

unread,
Aug 21, 2011, 11:48:29 AM8/21/11
to nhu...@googlegroups.com

If you could raise a JIRA and reference this thread, that would be great.

I'm not sure off the top of my head what causes ConvertChecked over just Convert.

> --
> You received this message because you are subscribed to the Google Groups "nhusers" group.
> To post to this group, send email to nhu...@googlegroups.com.
> To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
>

Nadav Ben-Gal

unread,
Aug 21, 2011, 1:53:03 PM8/21/11
to nhusers
opened:
https://nhibernate.jira.com/browse/NH-2850
fix the components and priority if it is not right...
hope i explained well the problem and what I've found.

Richard Brown

unread,
Aug 21, 2011, 2:46:15 PM8/21/11
to nhu...@googlegroups.com

Cheers.

I am pretty sure there's already at least one test that uses an enum.  Any help reproducing the ConvertChecked expression tree would be helpful too.

Reply all
Reply to author
Forward
0 new messages