我正在尝试使用 MiniProfiler.Integrations.MySql 以及 Dapper.Contrib 扩展来分析发送到 MySql 服务器的 sql 查询。我正在使用自己的 ConnectionFactory:
public IDbConnection GetConnection()
{
var connection = (DbConnection) new MySqlConnection(_connectionString);
return new ProfiledDbConnection(connection, CustomDbProfiler.Current);
}
Dapper.Contrib 允许插入新记录,就像
public async Task AddAsync(TEntity sample)
{
using (var connection = _connectionFactory.GetConnection())
{
await connection.InsertAsync(sample);
}
}
但是 ProfiledDbConnection
被解释为 SQLConnection
,产生与 MySQL 不兼容的 SQLServer 语法:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[Id], [CreatedAt], [AndSoOn]' at line 1
寻求您关于如何解决问题并使 MiniProfiler 正常工作的建议。
我正在使用(全部来自 Nuget):
简洁:1.50.5
Dapper.Contrib:1.50.5
迷你分析器:3.2.0
MiniProfiler.Integrations.MySql:1.0.1
最佳答案
作为解决方法,在当前版本中,您可以覆盖 Dapper.Contrib 中基于类型的名称解析,如下所示:
SqlMapperExtensions.GetDatabaseType = conn => "MySqlConnection";
这将覆盖默认的基于connection.GetType()
的名称行为。不过,这还不够好,我会看看我们是否可以在下一个 Dapper 版本中改进这一点。
关于c# - Dapper.Contrib 和 MiniProfiler(适用于 MySql)集成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50581540/