I'm trying to use MiniProfiler.Integrations.MySql along with Dapper.Contrib extensions to profile the sql queries sent to MySql server. I'm using my own ConnectionFactory:
public IDbConnection GetConnection()
{
var connection = (DbConnection) new MySqlConnection(_connectionString);
return new ProfiledDbConnection(connection, CustomDbProfiler.Current);
}
Dapper.Contrib allows inserting new records as simple as
public async Task AddAsync(TEntity sample)
{
using (var connection = _connectionFactory.GetConnection())
{
await connection.InsertAsync(sample);
}
}
But ProfiledDbConnection
is interpreted as an SQLConnection
, producing SQLServer syntax which is incompatible with MySQL:
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
Looking for your advice on how to solve the issue and get MiniProfiler working.
I'm using (all from Nuget):
Dapper: 1.50.5
Dapper.Contrib: 1.50.5
MiniProfiler: 3.2.0
MiniProfiler.Integrations.MySql: 1.0.1
Looks like I've found a workaround for the
Insert()
andInsertAsync()
methods, they accept ISqlAdapter as an optional parameter which seems to fix the issue (but still I can't use this approach forUpdate()
/UpdateAsync()
). This is due to the fact that when you want to useMiniProfiler
withMySQL
andDapper.Contrib
you need to wrap theMySqlConnection
which leads toDapper.Contrib
using the default (wrong)ISqlAdapter
.