Hello.
These are the classes:
public class Child
{
public int Id { get; set; }
public int Name { get; set; }
}
public class Parent
{
public int Id { get; set; }
public IList<Child> Children { get; set; }
}
when I want to remove a child from the collection, I would write something like:
currentParent.Children.Remove(toBeDeletedChild);
the problem is when the line above wants to be executed, I get numerous database queries.
It seems that it works like a loop that queries all children and searches for such a child. Pseudo:
foreach(child in currentParent.Children)
if(child==toBeDeletedChild)
delete(child);
This means that I get 100 database queries to remove a child from a parent with 100 children.
I am using NH3 and Fluent Nhibernate
Parent class mapping:
HasMany(p => p.Children)
.LazyLoad()
.Inverse()
.Cascade.AllDeleteOrphan();
source
share