找不到网络核心 NHibernate System.Data.SQLite
Net Core NHibernate System.Data.SQLite could not be found
我正在 Net Core 2.0 上编写控制台应用程序。我的应用程序使用 NHibernate Fluent 来处理 SQLite 本地数据库。
这是我配置 NHibernate 的方式:
public class NHibernateHelper
{
private static ISessionFactory _sessionFactory;
public static ISession OpenSession()
{
var dbConnectionString = @"Data Source=|DataDirectory|\TestDb.sqlite;Version=3;Password=;Foreign Keys=True;Page Size=1024";
_sessionFactory = Fluently.Configure().Database(SQLiteConfiguration.Standard.ConnectionString(dbConnectionString)
.ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateHelper>())
.ExposeConfiguration(cfg => new SchemaExport(cfg)
.Create(true, true))
.BuildSessionFactory();
return _sessionFactory.OpenSession();
}
public static void CloseSession()
{
_sessionFactory.Close();
_sessionFactory.Dispose();
}
}
当我尝试构建配置时收到异常:
我添加了以下来自 Nuget 的引用:
- FluentNHibernate (2.1.2)
- NHibernate (5.1.3)
- System.Data.SQLite (1.0.108)
我的本地数据库是使用 SQLite Studio 创建的,数据库类型=System.Data.SQLite。
我做错了什么?也许我使用了错误的提供商?
我找到了解决方案。
步骤 1 在您的项目中使用包 [System.Data.SQLite.Core 1.0.109]。
步骤 2 下载包 [System.Data.SQLite.Core 1.0.109.1].
步骤 3 复制 [运行times] 包 [System.Data.SQLite 1.0.109.1] 中的文件夹到您的项目文件夹,并遵循文件映射。
[package] --> [project folder]
runtimes/win-x86/lib/netstandard2.0/SQLite.Interop.dll --> runtimes/win-x86/native/SQLite.Interop.dll
runtimes/win-x64/lib/netstandard2.0/SQLite.Interop.dll --> runtimes/win-x64/native/SQLite.Interop.dll
runtimes/linux-x64/lib/netstandard2.0/SQLite.Interop.dll --> runtimes/linux-x64/native/SQLite.Interop.dll
runtimes/osx-x64/lib/netstandard2.0/SQLite.Interop.dll --> runtimes/osx-x64/native/SQLite.Interop.dll
那么您的 *.csproj 文件应包含以下内容。
<ItemGroup>
<None Update="runtimes\linux-x64\native\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes\osx-x64\native\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes\win-x64\native\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes\win-x86\native\nssm.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes\win-x86\native\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
第 4 步只需构建并运行您的应用程序。
PS:原因包 [System.Data.SQLite.Core 1.0.109] 未列出,您应该使用包 [System.Data.SQLite.Core 1.0.109]通过使用文本编辑器修改 *.csproj 文件。
2020 年 7 月更新
只需将 nuget 包 System.Data.SQLite.Core 添加到您的项目中,错误就会消失。
我正在 Net Core 2.0 上编写控制台应用程序。我的应用程序使用 NHibernate Fluent 来处理 SQLite 本地数据库。
这是我配置 NHibernate 的方式:
public class NHibernateHelper
{
private static ISessionFactory _sessionFactory;
public static ISession OpenSession()
{
var dbConnectionString = @"Data Source=|DataDirectory|\TestDb.sqlite;Version=3;Password=;Foreign Keys=True;Page Size=1024";
_sessionFactory = Fluently.Configure().Database(SQLiteConfiguration.Standard.ConnectionString(dbConnectionString)
.ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateHelper>())
.ExposeConfiguration(cfg => new SchemaExport(cfg)
.Create(true, true))
.BuildSessionFactory();
return _sessionFactory.OpenSession();
}
public static void CloseSession()
{
_sessionFactory.Close();
_sessionFactory.Dispose();
}
}
当我尝试构建配置时收到异常:
我添加了以下来自 Nuget 的引用:
- FluentNHibernate (2.1.2)
- NHibernate (5.1.3)
- System.Data.SQLite (1.0.108)
我的本地数据库是使用 SQLite Studio 创建的,数据库类型=System.Data.SQLite。
我做错了什么?也许我使用了错误的提供商?
我找到了解决方案。
步骤 1 在您的项目中使用包 [System.Data.SQLite.Core 1.0.109]。
步骤 2 下载包 [System.Data.SQLite.Core 1.0.109.1].
步骤 3 复制 [运行times] 包 [System.Data.SQLite 1.0.109.1] 中的文件夹到您的项目文件夹,并遵循文件映射。
[package] --> [project folder]
runtimes/win-x86/lib/netstandard2.0/SQLite.Interop.dll --> runtimes/win-x86/native/SQLite.Interop.dll
runtimes/win-x64/lib/netstandard2.0/SQLite.Interop.dll --> runtimes/win-x64/native/SQLite.Interop.dll
runtimes/linux-x64/lib/netstandard2.0/SQLite.Interop.dll --> runtimes/linux-x64/native/SQLite.Interop.dll
runtimes/osx-x64/lib/netstandard2.0/SQLite.Interop.dll --> runtimes/osx-x64/native/SQLite.Interop.dll
那么您的 *.csproj 文件应包含以下内容。
<ItemGroup>
<None Update="runtimes\linux-x64\native\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes\osx-x64\native\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes\win-x64\native\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes\win-x86\native\nssm.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes\win-x86\native\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
第 4 步只需构建并运行您的应用程序。
PS:原因包 [System.Data.SQLite.Core 1.0.109] 未列出,您应该使用包 [System.Data.SQLite.Core 1.0.109]通过使用文本编辑器修改 *.csproj 文件。
2020 年 7 月更新 只需将 nuget 包 System.Data.SQLite.Core 添加到您的项目中,错误就会消失。