2015-12-21 3 views
0

В мини Profiler документации вы можете сделать следующее:Servicestack позволяет MiniProfiler на собственном DB Connection

public static DbConnection GetOpenConnection() 
{ 
    var cnn = CreateRealConnection(); // A SqlConnection, SqliteConnection ... or whatever 

    // wrap the connection with a profiling connection that tracks timings 
    return new StackExchange.Profiling.Data.ProfiledDbConnection(cnn,  MiniProfiler.Current); 
} 

Как включить профилированное подключение к БД в Servicestack с использованием Servicestack версии реализации Miniprofiler на моем собственном подключении БД. У меня есть функция, которая возвращает строку соединения вместо использования встроенной базы servicestack.Db.

public static DbConnection GetOpenConnection(string ConnectionName) 
    { 
     string provider = ConfigurationManager.ConnectionStrings[ConnectionName].ProviderName; 
     string connectionstring = ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString; 

     DbProviderFactory factory = DbProviderFactories.GetFactory(provider); 
     DbConnection cnn = factory.CreateConnection(); 
     cnn.ConnectionString = connectionstring; 
     cnn.Open(); 
     //this is ServiceStack current profiler for request and response DTO's 
     Profiler profiler = Profiler.Current; 
     // I want to return a profiled db connection here that will include the connection profiles into the current Profiler data. 
     return cnn; 

    } 

ответ

1

Вы бы сделать то же самое, что делает Ormlite и просто обернуть вашу связь с MiniProfiler-х ProfiledDbConnection, например:

return new ProfiledDbConnection(cnn, Profiler.Current)