1

I am trying to AND multiple LINQ (rather lambda) Expressions into a where clause to query a local CosmosDb emulator.

The resulting query looks like this:

SELECT * FROM root 
WHERE ((root["ActivityName"] IN ("Run")) & (root["CreatedByUser"]["Id"] IN (10023))) 
ORDER BY root["CreatedOnUtc"] DESC

Note the bitwise & operator in the query. This leads to no results as the outcome despite of the fact that matching results actually exist in the CosmosDb.

When I run this query, I get the results

SELECT * FROM root 
WHERE ((root["ActivityName"] IN ("Run")) AND (root["CreatedByUser"]["Id"] IN (10023))) 
ORDER BY root["CreatedOnUtc"] DESC

The code that I am using to combine multiple lambda expressions is roughly:

Expression.And(first, second);

details for it can be found here:

How do I combine my Expressions to yield a query with logical AND instead of bit-wise &?

1
  • 2
    && -> Expression.AndAlso, || -> Expression.OrElse Commented Jul 7, 2018 at 21:21

1 Answer 1

1

Expression.AndAlso(first, second); is what you need.

As you said, Expression.And represents a bitwise AND operation while Expression.AndAlso represents a conditional (what you called logical) AND operation.

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.