ExpressionToSQL 产生无效查询

ExpressionToSQL produces invalid query

我正在使用带有 ExpressionToSQL nuget 包的 Dapper。我有一个查询如下:

Set = new Table{Schema = "Sch",Name = "tbl1"};
Columns = x => new { x.Id};
Conditions = x => x.Name== request.Name && x.Date == request.Date;

Where<TQueryIn, object> query = Sql.Select(Columns, Set).Where(Conditions);
...
connection.QueryAsync(query);

request.Name 的值为 "T1",request.Date 的值为“20121020”。

当我运行上述查询时,我得到以下查询:

SELECT a.[Id] FROM [Sch].[tbl1] AS a WHERE a.[Name] = @Name AND a.[Date] = @Date

如您所见,request.Namerequest.Date 的值已替换为 @Name@Date!

我要看的是:

SELECT a.[Id] FROM [Sch].[tbl1] AS a WHERE a.[Name] = 'T1' AND a.[Date] = '20121020'

绝对不是 Dapper 的问题,而是 ExpressionToSQL 包的问题。

有没有办法解决这个问题,并将 Expression<Func<T,bool>> 转换为具有上述输出的字符串值?

我对Dapper不熟悉,但是看了ExpressionToSQL中的测试,似乎可以在QueryAsync的第二个参数上提供参数,因此,我认为应该这样工作:

Set = new Table{Schema = "Sch",Name = "tbl1"};
Columns = x => new { x.Id};
Conditions = x => x.Name== request.Name && x.Date == request.Date;

Where<TQueryIn, object> query = Sql.Select(Columns, Set).Where(Conditions);
...
connection.QueryAsync(query, request);

也找到了这个,可能有用: https://dapper-tutorial.net/parameter-anonymous