Error : NHibernate.Hql.Ast.HqlBooleanExpression

707 views
Skip to first unread message

Christian I.

unread,
Sep 4, 2012, 4:33:34 PM9/4/12
to nhu...@googlegroups.com
Hello,

I have this error : 
{"Unable to cast object of type 'NHibernate.Hql.Ast.HqlBitwiseAnd' to type 'NHibernate.Hql.Ast.HqlBooleanExpression'."}

I create a predicate in C# with Expression Method, like this :
var listExpression = new List<Expression>();
var parameter = Expression.Parameter(typeof(T));

listExpression.Add(
Expression.Call(
((MemberExpression)memberExpression), "Contains", null,
Expression.Constant((string)MyValue))
);

Expression body = Expression.Constant(true);
foreach (var expression in listExpression)
body = Expression.And(body, expression);

The predicate looks like : see attachment.

I use this predicate like this :
session.QueryOver<Customer>().Where(prediate).List()

That's work when I have one condition in my predicate but I get the error when I have more than one

Any idea ?
4-09-2012 22-30-23.png

Ricardo Peres

unread,
Sep 4, 2012, 4:57:31 PM9/4/12
to nhu...@googlegroups.com
Use Expression.AndAlso, not Expression.And.

RP

Christian I.

unread,
Sep 5, 2012, 1:29:45 AM9/5/12
to nhu...@googlegroups.com
Thanks Ricardo that's work.

I have a bonus question. My predicate on the image join in the first post is : Param_0.LastName.Contains("..")

Is there a way to have : Param_0.LastName.ToUpper().Contains(".."). I'd like avoid difference between capital and not capital.

Thanks,

On Tuesday, September 4, 2012 10:57:31 PM UTC+2, Ricardo Peres wrote:
Use Expression.AndAlso, not Expression.And.

Ricardo Peres

unread,
Sep 5, 2012, 9:27:35 AM9/5/12
to nhu...@googlegroups.com
You will have to wrap your call to Contains() inside a MethodCallExpression that calls ToUpper() first. Similar to what you already have.

RP
Reply all
Reply to author
Forward
0 new messages