문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top