Ton*_*ony 6 fluent-nhibernate c#-4.0
我正在使用Fluent NHibernate,我喜欢它!我有一个小问题:启动时间大约是10秒,我不知道如何优化Fluent nHibernate为了使这个启动时间更少问题,我把它放在一个线程上.
有人可以解决这个问题吗?并回复以下代码修改,以提高性能?
我在这看到类似的东西:http: //nhforge.org/blogs/nhibernate/archive/2009/03/13/an-improvement-on-sessionfactory-initialization.aspx 但我不知道如何让这个一起工作与流利的nHibernate.
我的代码是这样的:
public static ISession ObterSessao()
{
System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;
string ConnectionString = ConfigurationHelper.LeConfiguracaoWeb("EstoqueDBNet"); // My Connection string goes here
var config = Fluently.Configure()
.Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(ConnectionString));
config.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()));
var session = config
.BuildSessionFactory()
.OpenSession();
System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Normal;
return session;
}
Run Code Online (Sandbox Code Playgroud)
Phill 有正确的答案,但要进一步了解一下 http://nhibernate.info/blog/2009/03/13/an-improvement-on-sessionfactory-initialization.html将 NHibernate 配置序列化为一个文件,因此您不必在每次启动应用程序时重建它。这可能会快一点,也可能不会快一点,具体取决于各种因素(主要是您拥有的映射数量) - 据此,是否有关于 NHibernate 与 Fluent NHibernate 启动性能的数据?
只是为了强调(基于答案评论中的一些后续 qns),您应该序列化 (NHibernate.Cfg.)Configuration 对象,而不是 SessionFactory。
然后,您Fluently.Configure(Configuration cfg)在创建 FluentConfiguration 时使用重载来注入配置(而不是让它自动为您构建配置)。
| 归档时间: |
|
| 查看次数: |
6579 次 |
| 最近记录: |