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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:51:27+00:00 2026-06-17T02:51:27+00:00

I have a problem where I have a many-to-many mappings in my table structure

  • 0

I have a problem where I have a many-to-many mappings in my table structure creating headaches when trying to edit a simple record.

Example layout of where I am having problems:

Facilities Many-to-One Locations
Facilities One-to-Many Users
Users Many-to-Many Locations
Users One-to-Many PreviousPasswords

If I make a change to a Facilities record (Change the name field) I get the following error upon save:

collection [Users.PreviousPasswords] was not processed by flush()

Mapping looks like:

public FacilitiesMap()
{
    Table("Facilities");

    Id(x => x.ID);
    Map(x => x.Name);
    HasMany(x => x.Users).KeyColumn("FacilitiesID").Cascade.AllDeleteOrphan().Inverse();
    HasMany(x => x.Locations).KeyColumn("FacilitiesID").Cascade.AllDeleteOrphan().Inverse();
}

public UsersMap()
{
    Table("Users");
    Id(x => x.ID);
    Map(x => x.FirstName);
    Map(x => x.LastName);
    References(x => x.Facilities, "FacilitiesID").ForeignKey("ID");
    HasMany(x => x.PreviousPasswords).KeyColumn("UsersID").Cascade.AllDeleteOrphan().Inverse();
    HasManyToMany<Locations>(x => x.Locations)
         .Schema("Members")
         .Table("UsersToLocations")
         .ParentKeyColumn("UsersID")
         .ChildKeyColumn("LocationsID")
         .LazyLoad()
         .Cascade.SaveUpdate().Inverse();
}

public LocationsMap()
{
    Table("Locations");

    Id(x => x.ID);
    Map(x => x.Name);
    References(x => x.Facilities, "FacilitiesID").ForeignKey("ID");
    HasMany(x => x.Patients).KeyColumn("LocationsID").Cascade.AllDeleteOrphan().Inverse();
    HasManyToMany<Users>(x => x.Users)
         .Schema("Members")
         .Table("UsersToLocations")
         .ParentKeyColumn("LocationsID")
         .ChildKeyColumn("UsersID")
         .Cascade.SaveUpdate();
}

public PreviousPasswordsMap()
{
    Table("PreviousPasswords");

    Id(x => x.ID);
    Map(x => x.Password);
    Map(x => x.DateTime);

    References(x => x.Users, "UsersID").ForeignKey("ID");
}

The only way I can do a successful update to the Facilities record is if I use the following function to get the record before changing and saving it:

public Facilities GetFacility(int id)
{
    return FluentSessionManager.GetSession()
        .CreateCriteria<Facilities>()
        .Add(Expression.Eq("ID", id))
        .SetFetchMode("Users", FetchMode.Eager)
        .SetFetchMode("Locations", FetchMode.Eager)
        .UniqueResult<Facilities>();
}

The problem with this method is that where there are 10,000 users it takes a long time to process this query. Or even worse, if we have 100 location as well, then it takes around 2 minutes to get the one Facilities record to edit.

I am sure there is some kind of issue in the Mapping. Not sure how to fix or even where to start. Any help with this would be greatly appreciated.
Thanks in advance.

  • 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-17T02:51:28+00:00Added an answer on June 17, 2026 at 2:51 am

    Do you really need all the users for the facility? When you only add users you can use

    HasMany(x => x.Users).ExtraLazyLoad();
    

    and to improve the query when really all subcollections are needed

    public Facilities GetFacility(int id)
    {
        var session = FluentSessionManager.GetSession();
    
        // ignore the result, we only want to cache the results in the session
        session.CreateCriteria<Facilities>()
            .Add(Expression.Eq("ID", id))
            .SetFetchMode("Users", FetchMode.Eager)
            .Future<Facilities>();
    
        return session.CreateCriteria<Facilities>()
            .Add(Expression.Eq("ID", id))
            .SetFetchMode("Locations", FetchMode.Eager)
            .FutureValue<Facilities>().Value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do many-to-many mapping, but have a problem with a code below.
I am trying to get a One-To-Many relation working. I have the following mappings:
I have problem with lazy loading in many-to-many. There is no exception and there
I have faced the same problem many times. The Same Problem was With This
This sounds like a problem many others have posted about, but there's a nuance
I have a problem when I try to count how many times a word
I have the problem that my view controller class has too many delegates and
Seems to be a problem that many people have, but all the answers I
I'm sure this is the kind of problem other have solved many times before.
This problem has bugged me so many times and i have now decided to

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.