1

all

Below is my query code:

var users = db.users.where(u=> u.id=5 && db.usergroups.any(d=>d.user_id=u.id))

Build the expression tree for the condition u.id=5 is easy, but who can tell me how to build the condition db.usergroups.any(d=>d.user_id=u.id)

thanks

3
  • The code looks fine. What is the problem? Do you mean to build the expression tree by hand? Commented Apr 5, 2014 at 10:09
  • I mean, with calls to the static methods of the Expression class? Commented Apr 5, 2014 at 10:10
  • This code is static, I just want to convert it to dynamic query Commented Apr 5, 2014 at 10:21

1 Answer 1

1

The simplest way to obtain the expression created by the C# compiler is to affect it to a variable of the correct type, and looking at it in a debugger; in your case:

Expression<Func<User, bool>> lambdaExpression =
    u => u.id == 5 && db.UserGroups.Any(d => d.user_id == u.id);

And then look at the lambdaExpression variable in a debugger.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.