![](/img/trans.png)
[英]No MigrationSqlGenerator found for provider '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 添加了以下引用:
我的本地數據庫是使用 SQLite Studio 創建的,數據庫類型=System.Data.SQLite。
我做錯了什么? 也許我使用了錯誤的提供商?
我找到了解決方案。
步驟 1在您的項目中使用包 [System.Data.SQLite.Core 1.0.109]。
步驟 2下載包 [System.Data.SQLite.Core 1.0.109.1]。
步驟 3將包 [System.Data.SQLite 1.0.109.1] 中的 [runtimes] 文件夾復制到您的項目文件夾,並使用以下文件映射。
[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 :casue package [System.Data.SQLite.Core 1.0.109] is unlisted, you should use package [System.Data.SQLite.Core 1.0.109] by modify *.csproj file with text editor.
2020 年 7 月更新只需將 nuget 包System.Data.SQLite.Core添加到您的項目中,錯誤就會消失。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.