如何使用Fluent NHibernate配置配置SysCache2二级缓存?
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(_connectionString)
.Cache(c => c.UseQueryCache())
.Dialect<FullTextSearchEnabledMsSql2008Dialect>()
.UseReflectionOptimizer())
.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
.BuildSessionFactory();
}
答案 0 :(得分:3)
我没有遇到任何麻烦。
public static ISessionFactory Create(string connectionString) {
// fluently configure an ms-sql 2008 database
return FluentNHibernate.Cfg.Fluently.Configure()
.Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.Is(connectionString))
.AdoNetBatchSize(50)
.FormatSql()
.UseReflectionOptimizer())
.Cache(c => c
.ProviderClass<NHibernate.Caches.SysCache2.SysCacheProvider>()
.UseQueryCache()
.UseSecondLevelCache()
.UseMinimalPuts())
.ExposeConfiguration(config => {
new NHibernate.Tool.hbm2ddl.SchemaExport(config)
.Drop(/* Output to console */ false, /* Execute script against database */ true);
})
.ExposeConfiguration(config => {
new NHibernate.Tool.hbm2ddl.SchemaExport(config)
.Create(/* Output to console */ true, /* Execute script against database */ true);
})
.Mappings(m => {
m.FluentMappings.Conventions.Setup(x => {
x.AddFromAssemblyOf<Mappings.AspectMap>();
x.Add(FluentNHibernate.Conventions.Helpers.AutoImport.Never());
});
m.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly());
})
.BuildSessionFactory();
}
答案 1 :(得分:0)
我认为你不能。您必须通过web.config配置它。