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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:58:21+00:00 2026-05-21T13:58:21+00:00

I have a simple many-to-many relationship between the User class and the Place class.

  • 0

I have a simple many-to-many relationship between the User class and the Place class. This relationship is represented by the User’s “Neighbourhood” property

public class User
{
  public virtual IList<UserPlace> Neighbourhood { get; set; }
}

The UserPlace class is just a component that adds a single piece of information to the relationship between a User and a Place:

public class UserPlace
{
  public virtual User User { get; set; }
  public virtual Place Place { get; set; }
  public virtual bool IsDefault { get; set; }
}

The relationship is mapped as follows:

public class UserMappings : ClassMap<User>
{
  //... other mappings

  HasMany(x => x.NeighbourHood)
            .Component(c =>
                           {
                               c.Map(x => x.IsDefault);
                               c.References(x => x.Place).Cascade.None();
                           }
            ).Not.LazyLoad().Cascade.SaveUpdate();
}

When a user is created a number of Places are loaded from the database and added to the user, with one of these being set to default. When the user is persisted, the associated UserPlace entities are also persisted.

The problem I’m experiencing is that each Place entity associated with a UserPlace is also updated. That’s not the desired effect, and I’ve tried preventing the Cascade to Place from taking place (pun not intended) by setting Cascade to None()… this doesn’t change anything, however.

I’ve only managed to stop this update from taking place by specifying that each property on Place should not be updated ([PropertyName].Not.Updated()). This works, but it’s not a solution.

Does anyone have any ideas on how I can prevent this from happening?

Edit: The Place entity mapping has DynamicUpdate() specified as well – so the entity really shouldn’t change when a user is saved.

PS! I don’t think it makes a difference to this scenario (but I may be wrong!), but consider this also: The Place entities are loaded outside of NHibernate (using ADO.NET and a stored procedure, because of some geospatial querying I couldn’t do with NHibernate) and then attached to the session by calling Session.Update() on each entity.

  • 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-21T13:58:21+00:00Added an answer on May 21, 2026 at 1:58 pm

    This is not a cascading problem. NH updates the places because you call session.Update with each place. What you write in the PS is absolutely related to the problem.

    When you call update on a detached entity NH can’t know if the state of the entity actually changed or not. To avoid querying the data before updating (two database round-trips) it blindly updates the data.

    To avoid this:

    • Set select-before-update (SelectBeforeUpdate in fluent)
    • Use session.Merge(place). It also performs a query before updating. Note that it has a return value which needs to be used.
    • Use session.Load(place.Id) to create a proxy of the place in question and assign it (note that NH loads the place again when accessing the proxy’s properties)
    • Use session.Lock(place, LockMode.None) to put the objects into the session.
    • Use an NH query to retrieve the Places.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple one-to-many (models.ForeignKey) relationship between two of my model classes: class
I have a fairly simple Many to One relationship between two classes: @Entity public
I have a simple many to many relationship set up between tasks and tags.
I have a simple application using ADO.NET EntityFramework using a many-to-many relationship between two
I've got a simple one to many relationship between tasks and priorities. class Task
I have a simple has many relationship between 2 entities in Core Data: Team
I have a simple one-to-many relationship. I would like to select rows from the
This should be really simple, but I have tried many solutions posted on the
I have a one to many relationship between Admins and Users. Admin has_many :users
I have a simple has_many/belongs_to relationship between Report and Chart. The issue I'm having

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.