我应该在我的 Visual Studio 项目中的哪个位置复制 SQLite 数据库,我是否需要从那里复制它?

Where in my Visual Studio project should I copy a SQLite database, and do I need to copy it from there?

我将 SQL Server Express 数据库迁移到 SQLite(使用我从 here 下载的实用程序)。

现在我想将此 SQLite 数据库添加到 Visual Studio 中的 C# 项目中。

我找不到关于应该存储在哪里的信息。关于该过程,似乎有一篇相当不错的文章 here,但对于放置数据库的位置有点模糊。它说,“第一步是将您的数据库复制到 Visual Studio 项目中,然后从属性 window 中将构建操作设置为内容 。”

那么数据库文件应该或必须放在特定的位置吗?

此外,我可以在应用程序代码中查询时将数据库留在那里吗,还是需要将其复制到用户的 ApplicationData.Current.LocalFolder?

那篇文章似乎至少强烈暗示了这一点,文章显示了这样做的代码。

So is there a specific place where the database file should, or must, be placed?

你可以把它放在你项目的根目录下。如果您喜欢遵循特定的文件夹结构,您也可以这样做,但对于必须将 sqllite 数据库文件存储在何处没有任何限制。

Also, can I leave the database there while querying it from within the application code, or does it need to be copied to the user's ApplicationData.Current.LocalFolder? That is what seems to be at least strong implied by that article, which shows code for doing so.

当您在 构建操作 中将文件 属性 设置为 Content 时,该文件将被复制到您的输出目录,ReleaseDebug 目录,具体取决于您当前的构建配置,ApplicationData.Current.LocalFolder 指的是您的应用程序所在的文件夹 运行,因此只需设置 Build actionContent.

按照 Dipen Shah 的指示,我 right-clicked 项目,选择添加... > 现有项目,将 SQLite 数据库添加到项目,然后设置 构建操作 属性 的数据库文件到 Content - 再简单不过了!

这样做会将以下条目添加到我的 .csproj 文件中:

<ItemGroup>
    <None Remove="F4FDataSQLite_SingleTable.db" />
</ItemGroup>

<ItemGroup>
    <Content Include="F4FDataSQLite_SingleTable.db" />
</ItemGroup>