2015-12-21 21 views
0

在迷你探查文檔,你可以做到以下幾點:Servicestack使MiniProfiler在自己的數據庫連接

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); 
} 

我怎麼能使用我自己的數據庫連接的Miniprofiler實施Servicestack版本Servicestack成型的數據庫連接。我有一個函數返回一個連接字符串,而不是使用內置base.Db的servicestack。

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,e.g的連接:

​​