我试图从数据库中获取索引碎片信息。
这里的dapper sql查询:
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();
参数未通过预期的位置。
有人可以建议 - 也许还有另一种方法可以通过它们吗?
你使用的是文字字符串"@dbName"
和"@tableName"
,而不是参数的值。
移除围绕它们的N'
和'
。