Why does NHibernate delete reference objects one at a time rather than using a foreign key?

I have a simple relation Parent- Childit Parenthas many objects Child, the relation is unidirectional:

public class Parent
{
    public virtual int Id { get; protected set; }
    public virtual string Name { get; set; }
    public virtual IList<Child> Children { get; set; }
}

public class Child
{
    public virtual int Id { get; protected set; }
    public virtual string Name { get; set; }
}

Mapping for the cascade relationship set to AllDeleteOrphanto remove objects Childthat are not referenced Parent:

HasMany(x => x.Children).Cascade.AllDeleteOrphan();

And now I clear the list of objects Child:

var parent = session.Get<Parent>(1);
parent.Children.Clear();
session.Update(parent);

NHibernate deletes the object Childas expected, but it does this by sending a separate DELETE request for each Childof the collection: DELETE FROM Child WHERE Id = ...- this can mean really many requests.

, , DELETE FROM Child WHERE ParentId = 1. NHibernate ? , , ( , ..)?

+5
2

NHibernate .

.

+2

NHibernate a NHibernate: UPDATE "Child" SET Parent_id = null WHERE Parent_id = @p0;@p0 = 1 . , , , chuild , .

. , NH /.

, sqldeletes, .. NH - .

0

All Articles