Yoann. B
Yoann. B

Reputation: 11143

Configuration SysCache2 With Fluent NHibernate

How can i configure SysCache2 2nd-Level Cache with Fluent NHibernate configuration ?

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

Upvotes: 3

Views: 1518

Answers (2)

Ciel
Ciel

Reputation: 17752

I didn't have any trouble with it.

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

Upvotes: 3

cbp
cbp

Reputation: 25628

I don't think you can. You have to configure it through web.config.

Upvotes: 0

Related Questions