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

  • Home
  • SEARCH
  • 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 8046905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:56:18+00:00 2026-06-05T05:56:18+00:00

I need to load a property on an object that is set for lazy

  • 0

I need to load a property on an object that is set for lazy load. When I try to access it or load it using NhibernateUtil.Initialize(), I get the same error:

“Initializing[ProjectName.Logic.Entities.AddressList#9]-Could not initialize proxy – no Session.”

I can ensure that the session DOES exist by calling the necessary method to open a session in the “using” clause. (We have buried our session creation such that instantiating a repository object with a parameter of “true” will also create a session factory if needed and open a session. Verified with a breakpoint triggered at the “using” clause.)

foreach (MemberViewModel MVM in _filteredMemberViewModels)
           {
               foreach (Detail Mailings in MVM.Member.Mailings)  
               {
                   //used for lazy loading
                   using (var repo = new AddressListRepository(true))
                   {
                       NHibernateUtil.Initialize(Mailings.AddressList);
                   }
               }
           }

Detail Mapping:

public class DetailMap : ClassMap<Detail>
{
    public DetailMap()
    {
        Table("AddressDetailsCCN");

        // Unique Identifier
        Id(x => x.Id, "Id")
            .GeneratedBy.Identity();

        // MANY TO ONE relationship (the list has many details)
        References<AddressList>(x => x.AddressList, "ListId")
            .LazyLoad()
            .Not.Nullable()
            .Cascade.None();

        // MANY TO ONE relationship (Members have details)
        References<Member>(x => x.Member, "MemberId")
            .Not.LazyLoad()
            .Not.Nullable();

        // First line of Address
        Map(x => x.Address, "Address")
            .Nullable();

        // Second line of Address
        Map(x => x.Address2, "Address2")
            .Nullable();

        // City
        Map(x => x.City, "City")
            .Nullable();

        // State
        Map(x => x.State, "State")
            .Nullable();

        // Zip
        Map(x => x.Zip, "Zip")
            .Nullable();

        // Finalized date
        Map(x => x.FinalizedDate, "FinalizedDate")
            .CustomType(typeof(DateTime))
            .Nullable();

        // Date the list is created by
        Map(x => x.CreatedDate, "CreatedDate")
            .CustomType(typeof(DateTime))
            .Not.Nullable();
    }
}
  • 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-06-05T05:56:20+00:00Added an answer on June 5, 2026 at 5:56 am

    You need to attach your Mailings object to the session before you can initialize any properties on it. You would have to expose a method on your repository to do so, which would call:

    session.Lock(entity, LockMode.None);
    

    That will then associate the entity (Mailings) with your session and then the call to NHibernateUtil.Initialize(Mailings.AddressList) should work.

    However I would suggest re-considering why you need to do it this way and look at having coarser grained sessions (ie. open it earlier and close it later).

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

Sidebar

Related Questions

The Junits I have in my project need to load property files from the
i need to load a checkbox dynamically and set its state based on some
i need to load a library from my module using Modular Extensions my structure
I need to load an XML source using Simple XML, duplicate an existing node
Consider this typical disconnected scenario: load a Customer object from SQL Server using LINQ
I know that if I retain an IBOutlet by using property then I have
I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
I need to convert from a string that contains data to an object of
If I'm sending object named Property which have Photos collection when I'm need only
I need to load an image from a web in a simple Java stand

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.