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.