Running NHibernate3.3&CouchBase successfully

本文介绍如何配置NHibernate使用Couchbase作为二级缓存提供者,并提供了具体的配置示例,包括Couchbase.NET客户端库配置及NHibernate配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

将NHibernate升级到3.3,并使用最新的Couchbase,二级缓存不起作用,该文章可解决这个问题,我自己实验已经配置好可用

nhibernate-caches-couchbase

2nd level caching provider for NHibernate using Couchbase.

This provider is a port of the Enyim.Caching provider that is part of NHContrib - http://sourceforge.net/projects/nhcontrib/.

Usage

Once configured, the Couchbase NHibernate 2nd level cache should be transparent.

Configure the Couchbase .NET Client Library

<section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase" />

<couchbase>
  <servers bucket="default">
    <add uri="http://127.0.0.1:8091/pools" />
  </servers>    
</couchbase> 

Configure NHibernate

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider, NHibernate</property>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">
Server=localhost;initial catalog=nhibernate;Integrated Security=SSPI
</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="cache.provider_class"> NHibernate.Caches.Couchbase.CouchbaseCacheProvider,NHibernate.Caches.Couchbase</property>
</session-factory>
</hibernate-configuration> 

Using FluentNHibernate

    return Fluently.Configure()
    .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connectionString))
    .Cache(c => c.UseQueryCache().ProviderClass<CouchbaseCacheProvider>())
    .Mappings(m =>
        m.FluentMappings.AddFromAssemblyOf<Beer>())
    .ExposeConfiguration(c => c.SetProperty("current_session_context_class", "web"))
    .BuildSessionFactory();

Defaults

Without a "couchbase" config section, the provider will connect to a node on localhost using the default bucket.

转自:https://github.com/couchbaselabs/nhibernate-caches-couchbase

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值