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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:49:36+00:00 2026-06-12T02:49:36+00:00

I have a many to many relationship between two existing tables (User: UserId, Name)

  • 0

I have a many to many relationship between two existing tables (User: UserId, Name) and (Location: LocationId, Name), these can’t be changed. I have used an many-to-many mapping, but we have a new requirement to include history/future movements.

I have used the peoplesoft concept of effectively dating the records in a new intersect table (UserLocation: UserId, LocationId, EffectiveDate, Status) that replaces the old table, where the first 3 fields make up the primary key.

In SQL I can simply use the following statement to return the active record for the given effective date, but I can’t get anything like this from NHibernate (even get an error about parameters not working in multilevel select).

select l.*  
from location l  
where l.locationId in  
  (select ul.locationId  
   from UserLocation ul  
   where (ul.EffectiveDate =   
     (select max(ul_ed.EffectiveDate)  
      from UserLocation ul_ed  
      where ul.LocationId = ul_ed.LocationId  
        and ul.EffectiveDate = ul_ed.EffectiveDate  
        and ul.UserId - ul_ed.UserId  
        and ul.Status = true))  

I need to return back further filtered records by including parameters for UserId and EffectiveDate columns but would be happy to return everything to start with.

My issue however is the mapping classes (I use code mapping, not fluent) and can’t even get it close to working (limited NHibernate knowledge). I was hoping not to have to create a new class for the intersect table. I haven’t even got to the insert/update/delete part yet as I can’t even get select to work.

Requirements:
1. Insert new record in UserLocation when associating a user to a location with EffectiveDate = NOW, Status = True
3. Moving a user to a new location should insert new record in UserLocation with EffectiveDate = NOW, Status = True
4. Removing user from the location will insert new UserLocation record with EffectiveDate = NOW, Status = False
5. Retrieve the Locations the user is associated to on a given date.

Note: As reports are generated on this data we cannot delete the records, and data is also created for future events.

If someone could point me in the right direction to get started that would be appreciated. I have looked at Loader and Interceptor classes but can’t seem to make it fit.

  • 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-12T02:49:38+00:00Added an answer on June 12, 2026 at 2:49 am

    This is the answer we have come up with that works for the scenario described.

    Filter("EffectiveDate", mm => mm.Condition("Status = 1 and EffectiveDate = (select max(t1.EffectiveDate) from Table1 t1 where t1.Id = Id and t1.EffectiveDate <= :effectiveDate)"));
    

    Filters can be applied to the table, and to the mappings. However we ended up combining the 2 tables into a single table to reduce the complexity.

    Note: The Filter must be defined and applied to the session before it will be used in the mapping. See nHibernate doco for full details it quite well documented.

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

Sidebar

Related Questions

I have a many-to-many relationship between two tables, let's say Friends and Foods. If
Is it possible to have a many to many relationship between two tables, and
android noob... I have two tables, with a one to many relationship between country_tbl
I have a 1 to many relationship between two tables... say Organisation and Members
I have a Many-to-Many relationship between two tables. I'd like to sort the first
I have a many-to-many relationship between two tables: Order and Item. I need to
I have a one to many relationship between two tables. The many table contains
I have defined a many-to-many relationship between my two entity classes User and Permission.
I have two tables, users and groups . A user can belong to many
I have a many-to-many relationship between two models, Lists and Users. When a user

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.