SQLite-net 中的名称表

smi*_*erc 1 c# sqlite windows-8 windows-runtime sqlite-net

我正在构建一个使用 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;}
}
Run Code Online (Sandbox Code Playgroud)

然后创建一个表并通过以下方式在代码中输入初始数据:

    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",
                    })
                    );
        }
Run Code Online (Sandbox Code Playgroud)

我想创建多个帐户表,但db.CreateTable<Account>()语法只是创建一个表,数据插入到列中,db.Insert().我看不到在哪里输入表本身的名称。

我如何创建多个表,即一个名为“BusinessAccounts”和另一个基于 Account 类的“PersonalAccounts”?

有没有办法用 SQLite-net 做到这一点?或者我是否需要以某种方式明确写出 SQLite 命令?

小智 6

这个答案似乎已经过时,在 SQLite-net 中,您现在可以使用类上的属性来覆盖表名,例如:

[SQLite.Table("table_customers")]
public class Customer
    {
        [MaxLength(3)]
        public string code { get; set; }

        [MaxLength(255)]            
        public string name { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

所以它将创建/更新该表。