Dapper无法在单引号中识别通配符参数 [英] Dapper can't recognize wildcard param in the single quotes

查看:265
本文介绍了Dapper无法在单引号中识别通配符参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从数据库中获取索引碎片信息。

I am trying to get indexes fragmentation info from database.

这里是dapper sql查询:

Here the dapper sql query:

var result = await _dbConnection.QueryAsync<IndexFragmentationModel>($@"
        select
        a.index_id as Id, name as Name, avg_fragmentation_in_percent as FragmentationPercent 
        from sys.dm_db_index_physical_stats (DB_ID(N'@dbName'), OBJECT_ID(N'@tableName'), null, null, null) as a  
        join sys.indexes as b on a.object_id = b.object_id and a.index_id = b.index_id;    
        ", new
        {
            dbName = dbName,
            tableName = tableName
        });
        return result.ToList();

参数未传递期望的位置。

Parameters are not passing the the places where they are expected.

有人可以建议-也许还有另一种方法可以通过它们?

Could anybody please suggest - maybe there is another way to pass them ?

推荐答案

您正在使用文字字符串 @ dbName @ tableName ,而不是参数的值。

You're using the literal strings "@dbName" and "@tableName", not the parameters' values.

删除包围它们的 N''

这篇关于Dapper无法在单引号中识别通配符参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆