Dapper where子句IN数组,从对象类型System.Collections.Generic.List`1到已知的托管提供者本机类型

时间:2018-06-06 13:21:15

标签: c# dapper bulk

我想我正在遵循this post的解决方案 但我不知道为什么我收到此错误:从对象类型System.Collections.Generic.List`1到已知的托管提供程序本机类型

没有映射

这是我的代码:

public virtual IEnumerable<MyModel> QueryAllById(ICollection<string> ids)
{
    var sql = mySelectQuery + @"
                    WHERE SomeId IN @Ids                            
            ";            
    return Db.Query<MyModel>(sql, new { Ids = new[] { ids } });
}

1 个答案:

答案 0 :(得分:2)

您可以将ICollection转换为数组。

public virtual IEnumerable<MyModel> QueryAllById(ICollection<string> ids)
{
    var sql = mySelectQuery + @"
                    WHERE SomeId IN @Ids                            
            ";            
    return Db.Query<MyModel>(sql, new { Ids = ids.ToArray() });
}