开发者

Lazy loading BelongsTo relation with Castle Active Record?

I have the following mapping for a Relation in Castle AR

[BelongsTo("EVEN开发者_如何学编程T_ID", Lazy = FetchWhen.OnInvoke)]
        public EventType PayEvent
        {
            get
            {
                return m_PayEvent;
            }
            set
            {
                m_PayEvent = value;
            }
        }

But the Relation is fetched even if the property is not invoked.Is there anything missing here? I am using SessionScope as well.


It works for me. Make sure you have the entity marked as lazy and the properties and methods are all virtual.


in addition lazy-loading for BelongsTo relations does not work if you set NotFoundBehaviour to Ignore

Sample:

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


You cannot enable lazy loading with belogs to relationship.
See here.
You can implement it yourself.
Store the ID in your model and then:

    public ServicePlan PreviousServicePlan
    {
        get
        {
           if (previousServicePlan == null)
                previousServicePlan = ActiveRecordMediator<ServicePlan>
                    .FindByPrimaryKey(PreviousServicePlanId, false);

           return previousServicePlan;
        }

        private set 
        {
            previousServicePlan = value;
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜