导航插入报错 返回

public class Class1
{
[SugarColumn(IsPrimaryKey = true, ColumnName = "Id")]
public string Id { get; set; }
public string Name { get; set; }
public string ClassId { get; set; }
[Navigate(NavigateType.OneToOne, nameof(ClassId))]
public Class2 Class2 { get; set; }
}
public class Class2
{
[SugarColumn(IsPrimaryKey = true, ColumnName = "Id")]
public string Id { get; set; }
public string Name { get; set; }
}
DbScoped.SugarScope.InsertNav(class1)
.Include(z1 => z1.Class2)
.ExecuteCommand();
Id主键是GUID
导航插入后报错。
null value in column "classid" of relation "class1" violates not-null constraint”
再我使用一对多得时候能够正常生成GUID,能够插入成功
热忱回答(3)
-
fate sta VIP0
1个月前https://www.donet5.com/Home/Doc?typeId=2366
按模版提供完整可以重现的DEMO
0 回复 -
fate sta VIP0
1个月前public string ClassId { get; set; }=""; 或者加空默认值
0 回复 -
机智的大狸子 VIP0
1个月前已经解决,主键换成雪花ID都能自动生成了
0 回复