流利的Nhibernate约定和设置LazyLoad(Laziness.NoProxy)

时间:2011-08-25 13:28:08

标签: fluent-nhibernate

我一直在我的映射文件中的每个Reference上设置我对.LazyLoad(Laziness.NoProxy)的引用。

我想知道我是否可以通过我的流畅设置中的约定默认设置它?

1 个答案:

答案 0 :(得分:2)

我相信 IReferenceConvention 就是您所需要的:

public class ReferencesConvention : IReferenceConvention
{
    public void Apply(IManyToOneInstance instance)
    {
        instance.LazyLoad(Laziness.NoProxy);
    }
}

另外,请确保将约定添加到Fluent映射:

config.Mappings(m => 
        {
            // ......
            // Adding your Fluent mappings

            // Add all the custom conventions
            m.FluentMappings.Conventions.Add<ReferencesConvention>();
        });