Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 360047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:27:05+00:00 2026-05-12T12:27:05+00:00

How do I access a lazy loaded property of an ActiveRecord model from within

  • 0

How do I access a lazy loaded property of an ActiveRecord model from within the view?

I have a news model that Belongs to a Category Model, both of which are marked as Lazy=true

I’m able to access a lazy loaded property in my view by doing the following in my controller

using (new SessionScope())
{
    results = _service.FindAllNews(start, pageSize, new[] { Order.Asc("Id") });
    foreach (var result in results)
    {
        var category = result.Category;
    }
}
return View(results);

Then in my view, I parse through the results and display the category title with the following

<%= Html.Encode(item.Category.Title) %>

Obviously if I don’t reference the property in my controller, I will get a session scope error when trying to call the property in the view.

But this seems wrong to me. Is there a better way of initializing the lazy loaded properties of a model before reaching the view? I suppose I could write an Init function in the model, but that also seems wonky as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:27:05+00:00Added an answer on May 12, 2026 at 12:27 pm

    I turned to the AR google group and found the answer I was looking for. I thought I would share it with everyone here in case someone else is looking for the same thing.

    To change where the session scopes are created and destroyed for lazy loading with ActiveRecord, you should add the following to your web.config.

    <system.web>
        <httpModules>
            <add 
                name="ar.sessionscope" 
                type="Castle.ActiveRecord.Framework.SessionScopeWebModule, Castle.ActiveRecord" />
        </httpModules>
    </system.web>
    

    This changes where the session scope is created and disposed to match the session scope per request here http://www.castleproject.org/activerecord/documentation/trunk/usersguide/web.html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Hibernate domain object that gets loaded by different parts of the
I'm developing a project that has multiple programs that share a single, lazy loaded
In our .Net application, some of our business objects use lazy loading to access
I have a many-to-many relationship between the two entities called events and artists, both
Is there any way that each child of a collection will be loaded individually
I am running into the org.hibernate.LazyInitializationException error when I try to access a lazy
I have conversion tables I need to contain in memory for fast access. Until
I have a database schema that stores one Page with many Revisions. Like a
that's what I have: a Windows Service C# multithreaded the service uses a Read-Write-Lock
Is there a way to disable LINQ's object tracking features, without also disabling lazy-loaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.