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 6066505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:30:29+00:00 2026-05-23T09:30:29+00:00

I have two entities having one to many relation and these are User and

  • 0

I have two entities having one to many relation and these are User and Address. One user can have many addresses. I am using one session and transaction per HTTP request pattern and Level 1 cache is turned on. For some reason I am seeing that my lazy loaded collections are not taking care of changes made to the data. For example If I create one user object. Then I create two address objects and save them like

User u1 = CreateNewUser("olduser@xyz.tld", "olduser@xyz.tld");
u1.Save();

Address a1 = CreateNewAddress(u1, "olduser@xyz.tld", "Old1", "User1");
a1.Save();
Address a2 = CreateNewAddress(u1, "olduser@xyz.tld", "Old1", "User1");
a2.Save();
Session.Flush();
Assert.AreEqual(2, u1.Addresses.Count); // THIS IS FAILING BECAUSE COUNT IS 0

Now when doing assert I am expecting user object to lazy load two address and count should be 2 but it returns 0. If I simply throw away complete cache by doing Session.Clear() call that doesn’t work either. But if I throw away complete cache by doing Session.Clear() and then load my user object again this way it works as expected. I am not sure am I missing something or there is still something missing in NHibernate cache set-up configurations. Any help will be appreciated.

Thanks

  • 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-23T09:30:29+00:00Added an answer on May 23, 2026 at 9:30 am

    You will have to add the addresses to the user class too… Typically you see people creating a method u1.AddAddress(a1); which will set the reference to the user on the address object and add it to the address list in the user.

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

Sidebar

Related Questions

I have two entities, a User and Role with a one-to-many relationship from user
I have two entities, Entity1 and Entity2, on a one to many relationship. On
i have two Entities, Parent and Child, that are linked through a bidirectional one-to-many
I have two entities Foo and Bar with a Many to Many relationship between
I have two entities: Patient and Job. Patient has a to-many relationship to Job
I have following two entities public class User { [Key] public int Id {
I have a simple situation where I have two entities related with Many-To-Many relationship.
I'm having trouble mapping two entities together with Entity Framework CTP5 using Code First
I have two Hibernate entities named Alpha and Beta, and Alpha has a *-to-one
I have two entities, each from a different database and therefore different edmx files.

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.