级联插入 Insertable<T>().AddSubList() 如何实现多级插入? 返回
哪位能帮忙解答一下 级联插入 中如何实现多级级联插入。
例如:
[SugarTable("TestA")]
public class TestA
{
[SugarColumn(IsIdentity = true,IsPrimaryKey = true)]
public int IndexId { get; set; }
[SugarColumn(Length = 50)]
public string TestAName { get; set; }
[SugarColumn(IsIgnore = true)]
public List<TestB> BList { get; set; }
}
[SugarTable("TestB")]
public class TestB
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public int IndexId { get; set; }
[SugarColumn(ColumnDataType = "int")]
public int AIndexId { get; set; }
[SugarColumn(Length = 50)]
public string TestBName { get; set; }
[SugarColumn(IsIgnore = true)]
public List<TestC> CList { get; set; }
}
[SugarTable("TestC")]
public class TestC
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public int IndexId { get; set; }
[SugarColumn(ColumnDataType = "int")]
public int AIndexId { get; set; }
[SugarColumn(ColumnDataType = "int")]
public int BIndexId { get; set; }
[SugarColumn(Length = 50)]
public string TestCName { get; set; }
}
这样写只能保证A和B的级连插入,如何连同C一起添加数据啊?
return base.Context.Insertable(new TestA()
{
IndexId = 0,
TestAName = "TestA测试001",
BList = new List<TestB>(){
new TestB()
{
IndexId = 0,
AIndexId = 0,
TestBName = "TestB测试001",
CList = new List<TestC>()
{
new TestC()
{
IndexId = 0,
BIndexId = 0,
TestCName = "TestC测试001"
}
}
}
}
}).AddSubList(t => t.BList.First().AIndexId)
//.AddSubList(t=>t.BList.First().CList.First().AIndexId)
.ExecuteReturnPrimaryKey();
热忱回答(1)
-
fate stay night VIP0
2020/11/10后续支持 ,尽请关注
0 回复