无法在.NET Core上使用MiniProfiler配置MySQL

时间:2017-06-02 10:53:22

标签: mysql asp.net-core-mvc .net-core mvc-mini-profiler

我正在玩 .net核心并试图获得 asp.net核心 + mysql + dapper + mini-mvc-profiler 可以使用 Linux 。遇到mini-mvc-profiler的问题。

我正在使用:

<PackageReference Include="Dapper" Version="1.50.2" />
<PackageReference Include="MiniProfiler.AspNetCore" Version="4.0.0-alpha6-79" />
<PackageReference Include="MiniProfiler.Shared" Version="4.0.0-alpha6-79" />
<PackageReference Include="MySql.Data.Core" Version="7.0.4-IR-191" />

我有SQLProfiler类:

public class SQLProfiler
{
    public static DbConnection GetOpenConnection(string connectionString)
    {
        //return new MySqlConnection(connectionString); // that works OK         
        return new StackExchange.Profiling.Data.ProfiledDbConnection( 
            new MySqlConnection(connectionString), MiniProfiler.Current
        );
    }
}

从存储库类调用它:

using (var connection = SQLProfiler.GetOpenConnection(_connectionString))
{              
    return connection.Query<UserIdentityDTO>(sql, 
        new {
            myemail = email,
            mypassword = password,
            myprovider = PROVIDER_LOCAL
        }
    ).FirstOrDefault();                 
}

我明白了:

NullReferenceException: Object reference not set to an instance of an object.
MySql.Data.MySqlClient.MySqlConnection.set_Reader(MySqlDataReader value)

堆栈跟踪:

MySql.Data.MySqlClient.MySqlConnection.set_Reader(MySqlDataReader value)
MySql.Data.MySqlClient.MySqlCommand.ResetReader()
MySql.Data.MySqlClient.MySqlCommand.Dispose(bool disposing)
StackExchange.Profiling.Data.ProfiledDbCommand.Dispose(bool disposing) in ProfiledDbCommand.cs
System.Data.Common.DbCommand.Dispose()
Dapper.SqlMapper+<QueryImpl>d__124.MoveNext()
System.Collections.Generic.List..ctor(IEnumerable<T> collection)
System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
Dapper.SqlMapper.Query<T>(IDbConnection cnn, string sql, object param, IDbTransaction transaction, bool buffered, Nullable<int> commandTimeout, Nullable<CommandType> commandType)
persistance.dapper.repository.UserQueries.Get(string email, string password) in UserQueries.cs

1 个答案:

答案 0 :(得分:0)

正如Nick Craver所说,

 <ItemGroup>
    <PackageReference Include="Dapper" Version="1.50.2" />
    <PackageReference Include="DapperExtensions.DotnetCore" Version="1.0.1" />
    <PackageReference Include="MiniProfiler.AspNetCore" Version="4.0.0-alpha6-79" />
    <PackageReference Include="MiniProfiler.Shared" Version="4.0.0-alpha6-79" />
    <PackageReference Include="MySqlConnector" Version="0.30.0" />
  </ItemGroup>

......它还活着: - )