小编sjd*_*web的帖子

Dapper.net"where ... in"查询不适用于PostgreSQL

以下查询始终生成错误"42601:语法错误在或接近"$ 1" ".

connection.Query<CarStatsProjection>(
                @"select manufacturer, model, year, AVG(price) as averageprice, AVG(miles) as averagemiles, COUNT(*) as count
                        from products
                        where manufacturer IN @manufacturers 
                            AND model IN @models
                            AND year IN @years
                        group by manufacturer, model, year",
                new { manufacturers = new[] { "BMW", "AUDI" }, 
                      models = new[] { "M4", "A3" }, 
                      years = new[] { 2016, 2015 } });
Run Code Online (Sandbox Code Playgroud)

我通过在下面创建一个方法并在内部调用它来构建SQL查询来解决这个问题.想知道Dapper是否可以使用对象参数来处理这个问题吗?

 public static string ToInSql(this IEnumerable<object> values)
    {
        var flattened = values.Select(x => $"'{x}'");
        var flatString = string.Join(", ", …
Run Code Online (Sandbox Code Playgroud)

.net c# postgresql dapper

11
推荐指数
1
解决办法
2628
查看次数

标签 统计

.net ×1

c# ×1

dapper ×1

postgresql ×1