注册我的连接后,我想对其进行概要分析。使用下面的代码,我仅分析主连接( guepard )。
public static IDbConnectionFactory RegisterConnections(this Container self, bool enableProfiler)
{
var dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["guepard"].ConnectionString, SqlServer2008Dialect.Provider);
self.Register<IDbConnectionFactory>(
c =>
{
var cs = ConfigurationManager.ConnectionStrings;
dbFactory.RegisterConnection("gecko-log", cs["gecko-log"].ConnectionString, SqlServerDialect.Provider);
dbFactory.RegisterConnection("ksmpro", cs["ksmpro"].ConnectionString, SqlServer2012Dialect.Provider);
dbFactory.RegisterConnection("gestion-stock", cs["gestion-stock"].ConnectionString, SqlServerDialect.Provider);
dbFactory.RegisterConnection("planning", cs["planning"].ConnectionString, SqlServerDialect.Provider);
dbFactory.RegisterConnection("febus", cs["febus"].ConnectionString, SqlServerDialect.Provider);
if (enableProfiler)
dbFactory.ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current);
return dbFactory;
}
);
return dbFactory;
}
我不知道如何分析每个连接。 谢谢您的宝贵时间。
答案 0 :(得分:1)
您可以向OrmLiteConnectionFactory
注册ConnectionFilter
,例如:
dbFactory.RegisterConnection("gecko-log",
new OrmLiteConnectionFactory(cs["gecko-log"].ConnectionString,
SqlServerDialect.Provider,
setGlobalDialectProvider: false) {
ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
}
);
或者在注册每个NamedConnection工厂以设置ConnectionFilter
之后,例如:
OrmLiteConnectionFactory.NamedConnections.Values
.Each(f => f.ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current));