Consider the following filter:
var builder = Builders<Product>.Filter;
var filter = builder.Gte(i => i.Price, criteria.MinPrice) &
builder.Lte(i => i.Price, criteria.MaxPrice);
if (0 != criteria.CategoryId)
//Combine the following filter with the previous filter. How??
var criteriaFilter = builder.Eq(i => i.CategoryId, criteria.CategoryId);
How do I combine the criteriaFilter and filter?
if (criteria.CategoryId != 0)
{
var criteriaFilter = builder.Eq(i => i.CategoryId, criteria.CategoryId);
filter = filter & criteriaFilter;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With