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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:41:23+00:00 2026-06-15T07:41:23+00:00

There are several posts related to this error but I’m running into something different.

  • 0

There are several posts related to this error but I’m running into something different.

Very simple NHibernate scenario. Parent and child tables with one to many relationship. One parent can have multiple children.

I need to delete a Parent record with child records so I put together very basic code which works fine:

var childRecordList = new List<ChildRecord>();

var parentRecord = ParentRecordRepository.Get(parentRecordId);
childRecordList = ChildRecordRepository.GetAll().Where(c=>c.ParentRecord.Id==parentRecord.Id);

foreach(var childRecord in childRecordList)
{
 ChildRecordRepository.Delete(childRecord);
}

ParentRecordRepository.Delete(parentRecord);

Works. Deletes child and the parent records.

If I take the logic above and turn it into a Services method as “DeleteRecord(ParentRecord parentRecord)” it starts failing with the Illegal attempt to associate a collection with two open sessions error on ParentRecordRepository.Delete(parentRecord);

Services are called by instantiating a service class and then calling the DeleteRecord method:

var parentRecord = ParentRecordRepository.Get(id);

var recordService = new RecordService();
recordService.DeleteRecord(parentRecord);

Can’t figure out why. Help ?

  • 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-15T07:41:25+00:00Added an answer on June 15, 2026 at 7:41 am

    I tried creating a session by instantiating an instance of the repository and then doing operation on an object pulled from it.
    Then I would open a new session of the repository within the Service layer and try to delete the object passed from the controller created session with it. That was the problem.

    The bottom line is the same session has to used to both get and delete an object.

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

Sidebar

Related Questions

I know there are several threads and posts regarding this issue in the internet
There are several threads on this here at SO but I didn't find one
There are several other questions about this topic that I have gone through, but
There are several variant questions on this on SO, but I did not find
I know that there are several posts adressing this issue already. However I can't
I have read several posts related to my question on C. This indeed help
I see there are several posts regarding Cannot set Property and I'm still struggling
So, there have been several posts here about importing and saving data from an
There are several scripting environments available for .NET applications (e.g. this post ). My
I've found several posts on hubFS of people asking if there is, or will

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.