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)";