Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A child entity that was temporarily added and then deleted is still inserted #3665

Closed
sashakboo opened this issue Mar 20, 2025 · 0 comments
Closed

Comments

@sashakboo
Copy link
Contributor

sashakboo commented Mar 20, 2025

A child entity that was temporarily added and then deleted will still be inserted if the parent entity is reattached to a new session.

Book book = null;
using (var s = OpenSession())
using (var tr = s.BeginTransaction())
{
  book = new Book { Id = 1};
  book.Words = new List<Word> { new Word { Id = 1, Parent = book } };
  s.Save(book);
  tr.Commit();
}

// Adding temporary child on detached entity.
Word word = new Word { Id = 2, Parent = book };
book.Words.Add(word);

using (var s = OpenSession())
using (var tr = s.BeginTransaction())
{
  // Attach entity to new session and remove temporary child.
  s.Update(book);
  book.Words.Remove(word);
  // This produces insert command for removed child.
  tr.Commit();
}

Maybe it's a duplicate of #2028

Tests here:
#3666

sashakboo pushed a commit to sashakboo/nhibernate-core that referenced this issue Mar 20, 2025
@hazzik hazzik closed this as completed Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants