解决办法:在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)";