Is it possible to build a custom Expression<Func<T, bool>> by chaining "Or" operations to use in EF?
Hi all, this is my first post here.
I want to check if it's possbile to chain Expression.Or operations to be able to use it in EF 6 (Or in a
Let me explain the context:
a filter to bring orders from a single user would be :
since we can have many users, we would have many filter, one for each user:
Here comes the question: since it's not known how many users there are in the array, How can I create such an expression that chain
I tried to build Expressions and use
I want to check if it's possbile to chain Expression.Or operations to be able to use it in EF 6 (Or in a
IEnumerable.Where() in general. Let me explain the context:
- I have two entities called Orders and Users. Users can create multiple orders, and one Order is related to one single User.
- Orders have a "CreatedDate" field (so that it is populated with DateTime.Now in the database) and also "CreatedBy" representing the username that created it.
- Users have a field called "DateDisabled" nullable. When it is
, I can bring all his orders, but if it has a value, i will just bring orders dating from before he was disabled:nullorder.DateCreated <= user.DateDisabled.
To simplify:
a filter to bring orders from a single user would be :
since we can have many users, we would have many filter, one for each user:
var manyUsersOrders = _repository.Where(filter1 || filter2 || filter3 || ... || filterN); Here comes the question: since it's not known how many users there are in the array, How can I create such an expression that chain
Or operations like that dinamically?I tried to build Expressions and use
Expression.Or to join them together, but It returns a BinaryExpression and I don't know exactly how to use it to build the final expression. Any help?

