关于dapper in查询很慢

dynamicParams.Add("sitecode", new string[]{ "abc","efd","ert" }));
var sql ="select count(1) from Table1 where SiteCode in @sitecode";
var total = conn.ExecuteScalar<int>(sql, dynamicParams);

在 Sql Server 上,查询 unicode 时使用 unicode 和查询非 unicode 时使用 ansi 至关重要

改成
dynamicParams.Add("sitecode",new string[] { "abc","efd","ert" }.Select(p => new DbString{
    Value = p,
    IsAnsi = true
}));

  

参考链接
https://stackoverflow.com/questions/19362113/dapper-and-varchars

https://stackoverflow.com/questions/51052874/how-do-i-tell-dapper-to-use-varchar-for-a-list-of-params-in-a-where-clause-tha

https://stackoverflow.com/questions/10933366/sp-executesql-is-slow-with-parameters
posted @ 2021-08-17 09:57  Setli  阅读(149)  评论(0编辑  收藏  举报