This question is locked. New answers and comments are not allowed.
If I have two persisted classes, a parent and child with a one to many relationship what is the best way to check if the parent has any children?
I know I can have constraints on the database to prevent me from deleting the parent when children are present, or I can set a dependency to cascade delete, however I want to be able to see if I *can* delete, without actually trying.
I'd like to implement a CanDelete() property on my parent object, so that I can do things in the UI layer (like showing/hiding a delete button) depending on whether I can delete an object.
Currently I'm checking the count of the child list to see if it has any members:-
But I'm thinking this might not be the most efficient way... I'm not sure if by calling Count I'm forcing OA to load all children at a time when I might not need them.
Does anyone know of a better way to check for these dependant objects without having to load them?
Many thanks...
I know I can have constraints on the database to prevent me from deleting the parent when children are present, or I can set a dependency to cascade delete, however I want to be able to see if I *can* delete, without actually trying.
I'd like to implement a CanDelete() property on my parent object, so that I can do things in the UI layer (like showing/hiding a delete button) depending on whether I can delete an object.
Currently I'm checking the count of the child list to see if it has any members:-
private
IList<Child> children =
new
List<Child>();
public
IList<Child> Children {
get
{
return
children; } }
//...
public
bool
CanDelete() {
return
this
.Children.Count == 0;
}
But I'm thinking this might not be the most efficient way... I'm not sure if by calling Count I'm forcing OA to load all children at a time when I might not need them.
Does anyone know of a better way to check for these dependant objects without having to load them?
Many thanks...