我正在构建一个使用 SQLite 作为存储数据库的 Windows 8 C#/XAML 应用程序,并且我正在尝试使用 SQLite-net 语法创建多个表。
根据我目前的研究,表是基于类创建的。首先,我通过以下方式创建了一个“帐户”类:
public class Account
{
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public string Name { get; set; }
public string Type { get; set;}
}
然后创建一个表并稍后在代码中通过以下方式输入初始数据:
private static readonly string _dbPath =
Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "data.sqlite");
using (var db = new SQLite.SQLiteConnection(_dbPath))
{
db.CreateTable<Account>();
db.RunInTransaction(() =>
db.Insert(new Account()
{
Name = "MyCheckingAccount",
Type = "Checking",
})
);
}
我想创建多个帐户表,但是 db.CreateTable<Account>()
语法只是创建一个表,并将数据插入到带有 db.Insert().
的列中我看不到在哪里输入表本身的名称。
如何创建多个表,即一个名为“BusinessAccounts”的表和另一个基于 Account 类的“PersonalAccounts”?
有没有办法用 SQLite-net 做到这一点?或者我是否需要以某种方式显式写出 SQLite 命令?
最佳答案
这个答案似乎已经过时了,在 SQLite-net 中,您现在可以使用类的属性来覆盖表名,例如:
[SQLite.Table("table_customers")]
public class Customer
{
[MaxLength(3)]
public string code { get; set; }
[MaxLength(255)]
public string name { get; set; }
}
因此它将创建/更新该表。
关于c# - SQLite-net 中的名称表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17625435/