1

I've have implemented a nested data set model to show a hierarchy in my database. So for deleting leaf nodes, after removing nodes, I will shift nodes left by 2.
Implementing this idea in C# I developed this code:

    private void deleteSectionFromTable(section selectedSection)
    {
        int leftIndex = selectedSection.left_index;
        int rightIndex = selectedSection.right_index;
        dbContext.sections.DeleteOnSubmit(selectedSection);
        dbContext.SubmitChanges();
        var sectionWithLeftCondition = (from s in dbContext.sections
                                    where s.left_index > leftIndex
                                    select s);
        var sectionWithRightCondition = (from s in dbContext.sections
                                         where s.right_index > rightIndex
                                         select s);
        foreach (section s in sectionWithLeftCondition)
        {
            s.left_index -= 2;
        }
        foreach (section s in sectionWithRightCondition)
        {
            s.right_index -= 2;
        }
        dbContext.SubmitChanges();
    }

In my code, I used dbContext.SubmitChanges() instantly after DeleteOnSubmit since I'm not sure if in the next queries if deleted record will show up or not?
My Question: I want to know if LINQ is smart enought to exclude node with DeleteOnSubmit status from query results or not.

VSB
  • 9,825
  • 16
  • 72
  • 145

1 Answers1

0

In short, no, deleted objects will not be returned by subsequent queries on the same Table after you call SubmitChanges, but until you do they are still available for selection.

Basically as soon as SubmitChanges completes the data structures both on the SQL server and in the internal object tracking lists in the DataContext are updated to reflect the changes you have made, so subsequent queries should never return objects that you have deleted.

Which seems a little irrelevant here, since the queries you are running after the SubmitChanges call should never return the deleted item anyway.

Corey
  • 15,524
  • 2
  • 35
  • 68