Search code examples
c#dapperbulk

Dapper where clause IN array, No mapping exists from object type System.Collections.Generic.List`1 to a known managed provider native type


I think I am following the solution from this post but I am not sure why I am getting this error:No mapping exists from object type System.Collections.Generic.List`1 to a known managed provider native type

This is my code:

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

Solution

  • You can convert ICollection to Array.

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