データベース内の階層を表示するために、ネストされたデータ セット モデルを実装しました。したがって、リーフ ノードを削除するには、ノードを削除した後、ノードを 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()
すぐに使用しましたか? 私の質問: LINQ がクエリ結果からステータスを持つノードを除外するのに十分スマートかどうかを知りたいです。DeleteOnSubmit
DeleteOnSubmit