Sqlite插入报错 .NET9, Drive5.1.4.185,Sqlite9.0.3 返回

using SqlSugar;
namespace SugarTest
{
internal class Program
{
static void Main(string[] args)
{
var db = new SqlSugarClient(
new ConnectionConfig
{
DbType = DbType.Sqlite,
ConnectionString = "Data Source = data.db",
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
MoreSettings = new ConnMoreSettings { SqliteCodeFirstEnableDropColumn = true },
}
);
db.DbMaintenance.CreateDatabase();
db.CodeFirst.InitTables(typeof(RotorInfo), typeof(AxisSetting));
db.DbMaintenance.TruncateTable([typeof(RotorInfo), typeof(AxisSetting)]);
//db.Insertable(RotorInfo.Default).ExecuteCommand();//ok
db.Insertable(AxisSetting.Default).ExecuteCommand();//报错
db.InsertNav(RotorInfo.Default).Include(r => r.AxisSetting).ExecuteCommand();//报错
Console.Read();
}
}
[SugarTable("RotorInfo")]
public class RotorInfo
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
public int AxisSettingId { get; set; }
[Navigate(NavigateType.OneToOne, nameof(AxisSettingId))]
public AxisSetting AxisSetting { get; set; }
[SugarColumn(IsIgnore = true)]
public static RotorInfo Default =>
new() { Name = "Default", AxisSetting = AxisSetting.Default };
}
[SugarTable("AxisSetting")]
public class AxisSetting
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
[SugarColumn(IsNullable = true)]
public int RotorId { get; set; }
[Navigate(NavigateType.OneToOne, nameof(RotorId))]
public RotorInfo Rotor { get; set; }
public static AxisSetting Default { get; private set; } = new() { };
}
}
热忱回答(4)
-
cat232181 VIP0
1个月前0 回复 -
fate sta VIP0
1个月前0 回复 -
fate sta VIP0
1个月前这个对象有问题 不是导航,也没有加isignore=true
0 回复 -
cat232181 VIP0
1个月前@fate sta:ok,谢了
0 回复