PredicateBuilder "And" Method Doesn't Work

I uploaded the predicate builder , and it’s hard for me to work with the entity infrastructure. Here is my code: v_OrderDetail is an entity

var context = new OrdersEntities();

Expression<Func<v_OrderDetail,bool>> whereClause = w => true;                                         
var predicate = PredicateBuilder.True<v_OrderDetail>();              
predicate.And(w => w.Status == "Work");                             
var results = context.v_OrderDetail.AsExpandable().Where(predicate);

When I look at the results, I return every order. The predicate "And" does not seem to be perceived. When I look at predicate.parameters.count, it only shows 1. I'm not sure, but I expect it to show 2 after adding the second.

Any help is greatly appreciated.

+3
source share
1 answer

This is because it predicate.Anddoes not change predicate; instead, it returns a new one Expression<Func<v_OrderDetail, bool>>. You need to assign the result somewhere so you can use it.

, :

predicate = predicate.And(w => w.Status == "Work");      

, . , , , .

MSDN.

, , . , . ExpressionVisitor, node, .

+9

All Articles