mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-05 07:50:52 +08:00
update
92
联级保存.md
92
联级保存.md
@@ -43,54 +43,54 @@ class CagetoryParent
|
||||
[Fact]
|
||||
public void EnableAddOrUpdateNavigateList_OneToMany_Parent()
|
||||
{
|
||||
var repo = g.sqlite.GetRepository<CagetoryParent>();
|
||||
var cts = new[] {
|
||||
new CagetoryParent
|
||||
{
|
||||
Name = "分类1",
|
||||
Childs = new List<CagetoryParent>(new[]
|
||||
var repo = g.sqlite.GetRepository<CagetoryParent>();
|
||||
var cts = new[] {
|
||||
new CagetoryParent
|
||||
{
|
||||
new CagetoryParent { Name = "分类1_1" },
|
||||
new CagetoryParent { Name = "分类1_2" },
|
||||
new CagetoryParent { Name = "分类1_3" }
|
||||
})
|
||||
},
|
||||
new CagetoryParent
|
||||
{
|
||||
Name = "分类2",
|
||||
Childs = new List<CagetoryParent>(new[]
|
||||
Name = "分类1",
|
||||
Childs = new List<CagetoryParent>(new[]
|
||||
{
|
||||
new CagetoryParent { Name = "分类1_1" },
|
||||
new CagetoryParent { Name = "分类1_2" },
|
||||
new CagetoryParent { Name = "分类1_3" }
|
||||
})
|
||||
},
|
||||
new CagetoryParent
|
||||
{
|
||||
new CagetoryParent { Name = "分类2_1" },
|
||||
new CagetoryParent { Name = "分类2_2" }
|
||||
})
|
||||
}
|
||||
};
|
||||
repo.Insert(cts);
|
||||
//执行创建表,和插入数据:
|
||||
//INSERT INTO "EAUNL_OTMP_CT"("Id", "Name", "ParentId") VALUES('5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f', '分类1', '00000000-0000-0000-0000-000000000000'), ('5d90afcb-ed57-f6f4-0082-cb6c5b531b3e', '分类2', '00000000-0000-0000-0000-000000000000')
|
||||
//INSERT INTO "EAUNL_OTMP_CT"("Id", "Name", "ParentId") VALUES('5d90afcb-ed57-f6f4-0082-cb6d0c1c5f1a', '分类1_1', '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f'), ('5d90afcb-ed57-f6f4-0082-cb6e74bd8eef', '分类1_2', '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f'), ('5d90afcb-ed57-f6f4-0082-cb6f6267cc5f', '分类1_3', '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f'), ('5d90afcb-ed57-f6f4-0082-cb7057c41d46', '分类2_1', '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e'), ('5d90afcb-ed57-f6f4-0082-cb7156e0375e', '分类2_2', '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e')
|
||||
cts[0].Name = "分类11";
|
||||
cts[0].Childs.Clear();
|
||||
cts[1].Name = "分类22";
|
||||
cts[1].Childs.Clear();
|
||||
repo.Update(cts);
|
||||
//UPDATE "EAUNL_OTMP_CT" SET "Name" = CASE "Id"
|
||||
//WHEN '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f' THEN '分类11'
|
||||
//WHEN '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e' THEN '分类22' END
|
||||
//WHERE ("Id" IN ('5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f','5d90afcb-ed57-f6f4-0082-cb6c5b531b3e'))
|
||||
//Childs.Clear 后没有执行删除子集合操作,说明没有做完整的对比
|
||||
cts[0].Name = "分类111";
|
||||
cts[0].Childs.Clear();
|
||||
cts[0].Childs.Add(new CagetoryParent { Name = "分类1_33" });
|
||||
cts[1].Name = "分类222";
|
||||
cts[1].Childs.Clear();
|
||||
cts[1].Childs.Add(new CagetoryParent { Name = "分类2_22" });
|
||||
repo.Update(cts);
|
||||
//UPDATE "EAUNL_OTMP_CT" SET "Name" = CASE "Id"
|
||||
//WHEN '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f' THEN '分类111'
|
||||
//WHEN '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e' THEN '分类222' END
|
||||
//WHERE ("Id" IN ('5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f','5d90afcb-ed57-f6f4-0082-cb6c5b531b3e'))
|
||||
//INSERT INTO "EAUNL_OTMP_CT"("Id", "Name", "ParentId") VALUES('5d90afe8-ed57-f6f4-0082-cb725df546ea', '分类1_33', '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f'), ('5d90afe8-ed57-f6f4-0082-cb7338a6214c', '分类2_22', '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e')
|
||||
Name = "分类2",
|
||||
Childs = new List<CagetoryParent>(new[]
|
||||
{
|
||||
new CagetoryParent { Name = "分类2_1" },
|
||||
new CagetoryParent { Name = "分类2_2" }
|
||||
})
|
||||
}
|
||||
};
|
||||
repo.Insert(cts);
|
||||
//执行创建表,和插入数据:
|
||||
//INSERT INTO "EAUNL_OTMP_CT"("Id", "Name", "ParentId") VALUES('5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f', '分类1', '00000000-0000-0000-0000-000000000000'), ('5d90afcb-ed57-f6f4-0082-cb6c5b531b3e', '分类2', '00000000-0000-0000-0000-000000000000')
|
||||
//INSERT INTO "EAUNL_OTMP_CT"("Id", "Name", "ParentId") VALUES('5d90afcb-ed57-f6f4-0082-cb6d0c1c5f1a', '分类1_1', '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f'), ('5d90afcb-ed57-f6f4-0082-cb6e74bd8eef', '分类1_2', '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f'), ('5d90afcb-ed57-f6f4-0082-cb6f6267cc5f', '分类1_3', '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f'), ('5d90afcb-ed57-f6f4-0082-cb7057c41d46', '分类2_1', '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e'), ('5d90afcb-ed57-f6f4-0082-cb7156e0375e', '分类2_2', '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e')
|
||||
cts[0].Name = "分类11";
|
||||
cts[0].Childs.Clear();
|
||||
cts[1].Name = "分类22";
|
||||
cts[1].Childs.Clear();
|
||||
repo.Update(cts);
|
||||
//UPDATE "EAUNL_OTMP_CT" SET "Name" = CASE "Id"
|
||||
//WHEN '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f' THEN '分类11'
|
||||
//WHEN '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e' THEN '分类22' END
|
||||
//WHERE ("Id" IN ('5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f','5d90afcb-ed57-f6f4-0082-cb6c5b531b3e'))
|
||||
//Childs.Clear 后没有执行删除子集合操作,说明没有做完整的对比
|
||||
cts[0].Name = "分类111";
|
||||
cts[0].Childs.Clear();
|
||||
cts[0].Childs.Add(new CagetoryParent { Name = "分类1_33" });
|
||||
cts[1].Name = "分类222";
|
||||
cts[1].Childs.Clear();
|
||||
cts[1].Childs.Add(new CagetoryParent { Name = "分类2_22" });
|
||||
repo.Update(cts);
|
||||
//UPDATE "EAUNL_OTMP_CT" SET "Name" = CASE "Id"
|
||||
//WHEN '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f' THEN '分类111'
|
||||
//WHEN '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e' THEN '分类222' END
|
||||
//WHERE ("Id" IN ('5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f','5d90afcb-ed57-f6f4-0082-cb6c5b531b3e'))
|
||||
//INSERT INTO "EAUNL_OTMP_CT"("Id", "Name", "ParentId") VALUES('5d90afe8-ed57-f6f4-0082-cb725df546ea', '分类1_33', '5d90afcb-ed57-f6f4-0082-cb6b78eaaf9f'), ('5d90afe8-ed57-f6f4-0082-cb7338a6214c', '分类2_22', '5d90afcb-ed57-f6f4-0082-cb6c5b531b3e')
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user