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 ? , , ( , ..)?