Hi. First of all, I want to thank you for this project, I really like the idea of a tool that's somewhere in-between Dapper and EntityFramework :)
But currently, it's possible to make queries only out of very simple expressions (e.g. no conditional statements).
I'd like to have this code working:
await _repo.SearchAsync<MyEntity>(s => s.Prop1 == 3 && s.Prop2 == "test");
But it says "System.NotSupportedException: Operation: Expression 'AndAlso' is currently not supported."
Any plans for adding such functionality in the future?
UPD. I'm testing it on .net core 3.0, RepoDb.Mysql
RepoDb had thorough support on query tree expression.
See the codes here at 54. That address your concern, or, let me check this.
Also, the codes here mimics yours.
Btw, would you be able to share your model?
I tested this one using the codes below and it works.
[TestMethod]
public void TestMySqlConnectionQueryAsyncViaExpression()
{
// Setup
var table = Database.CreateCompleteTables(1).First();
using (var connection = new MySqlConnection(Database.ConnectionString))
{
// Act
var result = connection.QueryAsync<CompleteTable>(e => e.ColumnInt == 0 &&
e.ColumnVarchar == "Test").Result.FirstOrDefault();
// Assert
Helper.AssertPropertiesEquality(table, result);
}
}
I would assume that you are using the underlying method QueryAsync for your SearchAsync.
Thanks for the fast reply.
Yes, I'm using QueryAsync method like this:
public async Task<List<TEntity>> SearchAsync<TEntity>(Expression<Func<TEntity, bool>> expression) where TEntity : class
{
using var connection = _connectionFactory.GetConnection();
return (await connection.QueryAsync(expression)).ToList();
}
I was not fully precise when I provided an example of expression. In my case it also contains negation of a bool property:
await _repo.SearchAsync<MyEntity>(s => s.Prop1 == prop1 && !s.Prop2)
Without ! it works just fine.
Great, I have to look at this then. This is a UnaryExpression then I could not say that why RepoDb fails to it. I have to debug it first.
Thank you for this and will definitely will get back to you.
But as an alternative fix, you can use the code below.
await _repo.SearchAsync<MyEntity>(s => s.Prop1 == prop1 && s.Prop2 == false);
By the way, always use the AsList() method over ToList() method. It cast things if it is castable, that is much more faster when converting each item ;)
Just verified this one and this is a bug. It is very easy to replicate.

Thank you for this bug report.
The fix is available at RepoDb.Core (v1.10.11).
Most helpful comment
Thanks for the fast reply.
Yes, I'm using QueryAsync method like this:
I was not fully precise when I provided an example of expression. In my case it also contains negation of a bool property:
Without
!it works just fine.