我正在尝试使用"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);
}发布于 2018-09-26 21:53:09
请按照以下步骤操作
1.-创建SQLite连接。
2.-创建表
3.-插入到数据库中
var connection = new SQLiteAsyncConnection(YourDBPath);
connection.CreateTableAsync<Login>().Wait();
connection.CreateTableAsync<User>().Wait();
connection.InsertWithChildrenAsync(YourItem);https://stackoverflow.com/questions/52508560
复制相似问题