Question

When manipulating data using Linq, how often does the SubmitChanges() method have to be called?

In my project, there are a few tables related with foreign keys. In the creation SQL, these foreign keys are constrained so a record that is part of a relationship can't be deleted without the dependant records being deleted first.

Therefore, there is a specific order that records within a relation need to be deleted. Will I have to delete each record, and perform a SubmitChanges() function on the database each time, or can I perform all the deletes in one go?

EDIT: My main question is: Do the records get deleted on SubmitChanges() in the same order as you delete them in code?

Was it helpful?

Solution

You should try call it as little as possible, but there is a known issue with Linq2SQL when you have insert and deletes that is effectively replacing an entity. In those cases, it is best to call it as soon as possible after the delete and subsequent insert.

Here is a similar question I asked a while back.

OTHER TIPS

If you need to delete as a batch e.g. a single transaction, you should only call the SubmitChanges method once when you have marked all the objects to be deleted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top