SQL 语句在SSMS中执行非常快,在程序中 用Dapper 参数化查询就很慢

解决办法:在sql语句末尾添加OPTION(RECOMPILE)

例子:     

原 sql: string sql = $"select * from server_loginout_log  where {where} order by Date desc offset(@pageIndex - 1) * @pageSize rows fetch next @pageSize rows only ";

添加后sql : string sql = $"select * from server_loginout_log  where {where} order by Date desc offset(@pageIndex - 1) * @pageSize rows fetch next @pageSize rows only OPTION (RECOMPILE)";

原文地址:https://www.cnblogs.com/zhuyuchao/p/12209300.html