Deleting A Customer..

Posts   
 
    
invisiable
User
Posts: 3
Joined: 08-Nov-2006
# Posted on: 10-Nov-2006 13:52:08   

I want to delete a customer from Northwind database. I've looked example which deletes customer's order. It is easy to done.

// first remove the orderdetail rows of this order adapter.DeleteEntityCollection(orderToRemove.OrderDetails); // remove the order itself toReturn = adapter.DeleteEntity(orderToRemove);

But when thinking about customer, there are many relations. Customer-CustomerOrder (1-n), CustomerOrder-OrderDetails(1-n), Customer-CustomerCustomerDemo(1-n).

Is there any class to help me or am i have to do a loop for deleting customerOrders..? Can you send me code if you can.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Nov-2006 14:13:02   

You can set Cascade Delete for the required relations in the Database.

Otherwise a recursive loop of deletes is a must. You can make use of the Unit Of Work object to make things more granular. Where you can add entitied and entity collections to be deleted and then commit the action in one go (transactional).