在Fluent Nhibernate中禁用缓存以进行特定的覆盖 [英] Disabling caching in Fluent Nhibernate for a specific override

查看:97
本文介绍了在Fluent Nhibernate中禁用缓存以进行特定的覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用Fluent NHibernate的基于约定的映射。映射如下所示:

  .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())

对于大多数我们的对象来说,这是完美的,但是对于某些对象,我希望禁用二级缓存。不过看来我不能这样做。 Cache.None没有流畅的选项。我甚至尝试了Not.Cache(),但也没有奏效。



有没有人有任何想法,我可以禁用某些选定的模型对象的缓存

解决方案

好的,我在设法找到它之后, b $ b


  1. 删除快捷方式 Cache.Is(x => x.ReadWrite()

  2. 创建一个新的约定类:



 
public class CacheableConvention:IClassConventionAcceptance,IClassConvention
{
public void Accept(IAcceptanceCriteria criteria)
{
criteria.Expect(x => x.EntityType.IsNotAny(typeof(Content),typeof(InstanceSetting),typeof(Profanity))) ;
}

public void Apply(IClassInstance instance)
{
instance.Cache.ReadWrite();
}
}




  1. 将惯例添加到AutoMappings中。
  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?

解决方案

Ok, I managed to find it after some digging around jogged an idea:

  1. Remove the shortcut Cache.Is(x => x.ReadWrite()
  2. Create a new convention class:

public class CacheableConvention: IClassConventionAcceptance, IClassConvention 
{
    public void Accept(IAcceptanceCriteria criteria)
    {
        criteria.Expect(x => x.EntityType.IsNotAny(typeof(Content), typeof(InstanceSetting), typeof(Profanity))); 
    }

    public void Apply(IClassInstance instance)
    {
        instance.Cache.ReadWrite();
    }
}

  1. Add the convention to the AutoMappings.
  2. Done!

这篇关于在Fluent Nhibernate中禁用缓存以进行特定的覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆