Using Northwind as an analogy, I am basically trying to find all Orders that have Pickles AND Peanuts on them.
The code I'm using is (filterItems is an ArrayList of Item IDs):
bucket.Relations.Add(OrderEntity.Relations.OrderItemEntityUsingOrderId);
bucket.Relations.Add(OrderItemEntity.Relations.ItemEntityUsingItemId);
filter = new PredicateExpression();
foreach (string item in filterItems) {
if (filter.Count == 0) {
filter.Add(ItemFields.ItemId == item);
}
else {
filter.AddWithAnd(ItemFields.ItemId == item);
}
}
if (bucket.PredicateExpression.Count == 0) {
bucket.PredicateExpression.Add(filter);
}
else {
bucket.PredicateExpression.AddWithAnd(filter);
}
I have Orders with these two Items on them but the query is not returning any results. If I change filter.AddWithAnd to filter.AddWithOr, of course I get results. But I'm trying to get Orders with BOTH items on them.
Is there something that I'm fundamentally doing wrong to find all Orders with Item A AND Item B?
Thanks,
Jay