Skip to content

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

Closed as duplicate of#2028
@sashakboo

Description

@sashakboo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions