23

是否可以通过 FHN 在代码中配置 L2 缓存提供程序?

在以下配置中添加一行是我所追求的:

 return Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.FromConnectionStringWithKey("Temp")).ShowSql())
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<IMap>())
                .ExposeConfiguration(c => { })
                .BuildSessionFactory();

干杯

AWC

4

1 回答 1

31

这可以通过 FNH 实现,在下面的示例中,请参见“缓存”属性:

return Fluently.Configure(fileConfiguration)
  .Database(MsSqlConfiguration
    .MsSql2005
      .ConnectionString(c => c.FromConnectionStringWithKey("Temp"))
      .ShowSql()
      .Cache(c => c.ProviderClass(typeof(NHibernate.Cache.HashtableCacheProvider).AssemblyQualifiedName)
          .UseQueryCache()))
    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<IMap>())
    .ExposeConfiguration(c => {
        c.EventListeners.PostLoadEventListeners = new IPostLoadEventListener[] {new TestPostLoadListener()};
      })
    .BuildSessionFactory();

干杯

AWC


请注意,对于 Fluent NHibernate >= 3.4.0.0,配置似乎略有不同。从http://nuget.org/packages/NHibernate.Caches.SysCache为 SysCache 使用 nuget 包

return Fluently.Configure(fileConfiguration)
  .Database(MsSqlConfiguration
    .MsSql2005
      .ConnectionString(c => c.FromConnectionStringWithKey("Temp"))
      .ShowSql())
    .Cache(c => c.ProviderClass<SysCacheProvider>().UseQueryCache())
    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<IMap>())
    .ExposeConfiguration(c => {
        c.EventListeners.PostLoadEventListeners = new IPostLoadEventListener[] {new TestPostLoadListener()};
      })
    .BuildSessionFactory();
于 2010-01-08T17:03:04.137 回答