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

SqlSugar 沟通中
4 217

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() { };

    }

}

screenshot-20250319-162543.png

热忱回答4