This question is locked. New answers and comments are not allowed.
Hi All,
I have two tables one is parent and second is child table.when i delete a parent record , i want that corresponding child records sholuld also be deleted for this i have declared one filled of child table foreign key which is primary key of parent table but don't know how to delete parent record with child record.Please help.
I have two tables one is parent and second is child table.when i delete a parent record , i want that corresponding child records sholuld also be deleted for this i have declared one filled of child table foreign key which is primary key of parent table but don't know how to delete parent record with child record.Please help.
4 Answers, 1 is accepted
0
Ratndeep
Top achievements
Rank 1
answered on 21 Dec 2009, 05:15 AM
Can anyone post a solution for above query.I need it.
Thanks in advance.
Thanks in advance.
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 21 Dec 2009, 08:06 AM
Hi Ratndeep,
You should really take a look at the [Depend] attributte. See the docs here.
Basically, you apply it to the child list in your parent like:
public class Order
{
[OpenAccess.Depend]
private IList<OrderLine> orderLines = new List<OrderLine>();
}
This will make OA delete the "dependent" objects when the an instance of the Order class is deleted. It works as a "cascading delete" in sql.
Hope this suits your needs..
Update:
Another way to do it if this is a 1:m relationship is to use DeleleOrphans... See the docs here.
Regards
Henrik
You should really take a look at the [Depend] attributte. See the docs here.
Basically, you apply it to the child list in your parent like:
public class Order
{
[OpenAccess.Depend]
private IList<OrderLine> orderLines = new List<OrderLine>();
}
This will make OA delete the "dependent" objects when the an instance of the Order class is deleted. It works as a "cascading delete" in sql.
Hope this suits your needs..
Update:
Another way to do it if this is a 1:m relationship is to use DeleleOrphans... See the docs here.
Regards
Henrik
0
Ratndeep
Top achievements
Rank 1
answered on 21 Dec 2009, 10:56 AM
Thanks Henrik for replying.
Before posting my query on forum i had looked for it and come to know about cascading delete but was not sure that this is the clean way to do.
Before posting my query on forum i had looked for it and come to know about cascading delete but was not sure that this is the clean way to do.
0
IT-Als
Top achievements
Rank 1
answered on 21 Dec 2009, 02:45 PM
Hi Ratndeep,
So you solved the problem?
Anyway, the main difference between Depend and Delete Orphans is that the delete orphans is placed on the child and is only deleted when there are no more references to the instance (checked by OA).. Depend doesn't really check this: It just deletes the childs without checking.
Regards
Henrik
So you solved the problem?
Anyway, the main difference between Depend and Delete Orphans is that the delete orphans is placed on the child and is only deleted when there are no more references to the instance (checked by OA).. Depend doesn't really check this: It just deletes the childs without checking.
Regards
Henrik