DeleteOnSubmit() doesn’t perform Delete on child objects.

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
AKhan
Posts: 4
Joined: Wed 22 Sep 2010 17:17

DeleteOnSubmit() doesn’t perform Delete on child objects.

Post by AKhan » Mon 18 Oct 2010 15:27

We are having issues with physically deleting child records in a collection. Consider following Structure.
Customer -> ContactCollection - > ContactMethod Collection.
Customer has collection of Contacts and Contact has collection of ContactMethods. Bellow is something similar I am trying to do.


dbContext.DeferredLoadingEnabled = false;

dbContext.Customer.Attach(customer, originalCustomer);

foreach (Contact contact in customer.ContactCollection)
{
Var originalContact = getOriginalContact(contact.Id);
dbContext.Contacts.Attach(contact, originalContact);
foreach(ContactMethod method in contact.ContactMethodCollection)
{
Var originalConatactMethod = getOriginalContactMethod(method.Id);
If(method.DeleteItem)
{
dbContext.ContactMethods.Attach(method);
dbContext. ContactMethods.DeleteOnSubmit(method);
}
else
dbContext.ContactMethods.Attach(method, originalConatactMethod);
}
}
_ dbContext.SubmitChanges();


The code sample above doesn’t have statements for InsertOnSubmit() and it because Inser works fine for me. The code doesn’t throw any exception but even it run through the DeleteOnSubmit() Statement it doesn’t delete the record and neither does it run any Query for the Delete (checked using db monitor).

If I take out the Delete Statement and place it out side of the loop i.e. (directly delete the child without going throw each Contact and ContactMethod) it work just trigger delete statement.

Am I missing anything or is this not how DeleteOnSubmit should be used?

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Tue 19 Oct 2010 16:48

The DeleteOnSubmit() method marks that the entity should be deleted at the nearest SubmitChanges call:
http://www.devart.com/linqconnect/docs/ ... ubmit.html
When DeleteOnSubmit is executed, the entity should neither be removed from the corresponding collection nor deleted from the table.

Please tell us if you are observing a behaviour different from this.

AKhan
Posts: 4
Joined: Wed 22 Sep 2010 17:17

Post by AKhan » Fri 29 Oct 2010 14:35

I looked at different examples and codes for the delete, and I think i am doing every thing as suggested.
When DeleteOnSubmit is executed the entity is still attached and exist in both collection and table.

My issues is that i am calling DeleteOnSubmit on an inner Object (grandchild) of the main object (Customer), and it is part of the collection. The delete work on the first or 2nd level of objects but not at the deeper level.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Mon 01 Nov 2010 14:55

I will send you a test project, please check that it was not blocked by your mail filter. The following entities are used in the sample: Company -> Order -> Order Detail (each Company has a collection of Orders, each Order has a collection of Order Details). For a single Company entity, all of the corresponding Order Details are deleted.

Please specify if this scenario is similar to the one you are trying to perform; if not, please describe what should be changed in the sample, or send us your test project.

Post Reply