I am trying to combine 2 query filters with the mongodb driver, but the framework returns just "System.InvalidOperationException: 'x.MyBool2 is not supported.'"
All of the following expressions succeed, except the last one, where I am trying to execute the combined query.
What am I doing wrong?
public async Task GetTest()
{
Expression<Func<PostDto, bool>> filter = x => x.MyBool1 == true;
Expression<Func<PostDto, bool>> filter1 = x => x.MyBool2 == true;
Expression<Func<PostDto, bool>> filter2 = x => x.MyBool1 && x.MyBool2;
var andAlsoExpression = Expression.AndAlso(filter.Body, filter1.Body);
var combinedFilter = Expression.Lambda<Func<PostDto, bool>>(andAlsoExpression, filter.Parameters);
var result = await Collection.AsQueryable().Where(filter).ToListAsync();
var result1 = await Collection.AsQueryable().Where(filter1).ToListAsync();
var result2 = await Collection.AsQueryable().Where(filter2).ToListAsync();
var result3 = await Collection.AsQueryable().Where(x => x.MyBool1 && x.MyBool2).ToListAsync();
var result4 = await Collection.AsQueryable().Where(combinedFilter).ToListAsync();
Debugger.Break();
}