How to Build a WhereCondition from Expression Tree?

Nov 30, 2009 at 2:04 PM

I want to convert a Expression to a WhereCondition and use it to query a db.

the Expression is most like a BinaryExpression with only &&,||,>,<,==,etc opertions.

I fount Lephone.Linq.ExpressionParser<T>.Parse(Expression) Method in DbEntry.Net source code, but it only deal with ExpressionType.MemberAccess.

What should i do? Should i have to write it myself?


Dec 1, 2009 at 12:23 AM


Dec 1, 2009 at 1:32 AM

Not sure about what you are looking for, but there is the style of Linq:

var list = User.Find ( p => p.Age > 18 && (p.Enabled == true || p.WorkDays > 360) );

Dec 1, 2009 at 1:46 AM

User.Find() need a WhereCondition parameter, but all i have is a Expression or a LambdaExpression.

It seems i have to write it myself.

Dec 1, 2009 at 5:32 AM

Change DbObjectModel<User> to LinqObjectModel<User> so you will get the Find function with expressioin parameter.


Dec 1, 2009 at 9:06 AM
Edited Dec 1, 2009 at 9:08 AM

I'm new to Linq and I don't know how to build a Expression<Func<User, bool>> form a LambdaExpression.

Anyway, I wirte this ExpressionToWhereCondition function myself and i will post it here later.

Thx everybody!

Dec 3, 2009 at 12:22 PM