views:

236

answers:

2

I have the following mapping for a Relation in Castle AR

[BelongsTo("EVENT_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.

A: 

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;
        }
    }
the_drow
That's old documentation (for ActiveRecord RC1). Lazy BelongsTo has been implemented since.
Mauricio Scheffer
+2  A: 

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

Mauricio Scheffer