English 中文(简体)
如何在Castle Active Record中懒加载BelongsTo关系?
原标题:Lazy loading BelongsTo relation with Castle Active Record?

我有以下的Castle AR关系映射。

[BelongsTo("EVENT_ID", Lazy = FetchWhen.OnInvoke)]
        public EventType PayEvent
        {
            get
            {
                return m_PayEvent;
            }
            set
            {
                m_PayEvent = value;
            }
        }

但是,即使没有调用属性,关系也会被获取。这里缺少什么吗?我也使用了SessionScope。

最佳回答

这对我有用。确保您将实体标记为lazy,并且属性和方法都是虚拟的。

问题回答

此外,Belongs的酶载荷 如果你确定Ignore,关系不会奏效。

例子:

[BelongsTo("EVENT_ID", Lazy=FetchWhen.OnInvoke, NotFoundBehaviour:=NotFoundBehaviour.Ignore)] 




相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签