繁体   English   中英

sqlite-net-扩展名-InsertWithChildrenAsync

[英]sqlite-net-extensions - InsertWithChildrenAsync

我正在尝试使用“ sqlite-net-extensions”创建表。 但是问题总是返回错误。

返回的错误是“只读”。

我创建了两个模型来创建表。

型号->登录

[PrimaryKey, AutoIncrement, Column("login_id")]
    [Indexed(Name = "LoginId", Order = 2, Unique = true)]
    public int Id { get; set; }

    [NotNull, Column("login_user")]
    [Indexed(Name = "LoginId", Order = 1, Unique = true)]
    public string UserName { get; set; }

    [NotNull, Column("login_password")] public string Password { get; set; }

    [OneToOne("login_id", "Login")]
    public User User { get; set; }

型号->用户

[PrimaryKey, AutoIncrement, Column("user_id")]
    public int Id { get; set; }

    [NotNull, Column("user_name")]
    [Indexed(Name = "UserId", Order = 3, Unique = true)]
    public string Name { get; set; }

    [NotNull, Column("user_email")]
    [Indexed(Name = "UserId", Order = 2, Unique = true)]
    public string Email { get; set; }

    [ForeignKey(typeof(Login)), NotNull, Column("login_id")]
    [Indexed(Name = "UserId", Order = 1, Unique = true)]
    public int LoginId { get; set; }

    [OneToOne("login_id", "User", CascadeOperations = CascadeOperation.All, ReadOnly = false)]
    public Login Login { get; set; }

插入方式

public async Task InsertWithChildren(object o)
    {
        var connection = _sqliteWrapper.OpenDatabase();
        await connection.InsertWithChildrenAsync(o, recursive: true);
    }

继续下一步

1.-创建一个SQLite连接。

2.-创建表格

3.-插入数据库

 var connection = new SQLiteAsyncConnection(YourDBPath);
 connection.CreateTableAsync<Login>().Wait();
 connection.CreateTableAsync<User>().Wait();
 connection.InsertWithChildrenAsync(YourItem);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM