gpt4 book ai didi

sql - 哪种是使用 SQLite DB 的最佳方式?

转载 作者:搜寻专家 更新时间:2023-10-30 20:54:47 26 4
gpt4 key购买 nike

正在开发 Windows Store 8.1 应用。

我想在我的应用程序中本地保存一些数据,所以我使用 SQLite 创建了一个数据库并在其中添加了一些表,并且我已经从代码中向其中添加了一些数据。

以下哪一个是最佳选择?

1) 第一次打开应用时从代码创建数据库

2) 在解决方案文件夹中附加具有预定义结构的 DB 文件。

请为此建议我最好的解决方案。

最佳答案

对于我自己的应用程序,我使用第一个选项:在应用程序首次打开时创建数据库。

    public MyAppDataContext()
{
connection = new SQLiteConnection(new SQLitePlatformWinRT(), Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, DATABASE_NAME));

Initialize();
}

private void Initialize()
{
connection.CreateTable<Foo>();
connection.CreateTable<Bar>();
connection.CreateTable<Bas>();
}

无需担心每次启动应用程序时都会不必要地创建表,因为 SQLiteConnection.CreateTable 使用 create if not exists behind the scenes .

关于sql - 哪种是使用 SQLite DB 的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27055406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com