我已经实现了一个嵌套数据集模型来显示我的数据库中的层次结构。因此,对于删除叶节点,在删除节点后,我会将节点向左移动 2。
在 C# 中实现这个想法,我开发了这段代码:
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();
}
在我的代码中,我dbContext.SubmitChanges()
立即使用,DeleteOnSubmit
因为我不确定在下一个查询中是否会显示已删除的记录?
我的问题:我想知道 LINQ 是否足够聪明,可以DeleteOnSubmit
从查询结果中排除具有状态的节点。