2

We're using convention based mapping with Fluent NHibernate. The mapping looks like so:

            .Conventions.Add
            (
                Table.Is(x => string.Concat(x.EntityType.Name.ToLower(), "s")),
                PrimaryKey.Name.Is(x => "Id"),
                DefaultLazy.Always(),
                DefaultCascade.SaveUpdate(),
                AutoImport.Never(),
                Cache.Is(x => x.ReadWrite())
            )

For most of our objects this is perfect but on certain objects I wish to disable the 2nd level cache. However it doesn't appear that I can do this. There is no fluent option for Cache.None. I've even tried Not.Cache() but that didn't work either.

Has anyone got any ideas on how I can disable the cache for certain selected model objects?

4

1 回答 1

2

好的,经过一番挖掘后,我设法找到了它:

  1. 删除快捷方式 Cache.Is(x => x.ReadWrite()
  2. 创建一个新的约定类:
公共类CacheableConvention:IClassConventionAcceptance,IClassConvention
{
    公共无效接受(IAcceptanceCriteria 标准)
    {
        criteria.Expect(x => x.EntityType.IsNotAny(typeof(Content), typeof(InstanceSetting), typeof(Profanity)));
    }

    公共无效应用(IClassInstance 实例)
    {
        instance.Cache.ReadWrite();
    }
}
  1. 将约定添加到 AutoMappings。
  2. 完毕!
于 2012-12-13T12:38:02.703 回答