I am writing a Console App on Net Core 2.0. My App uses NHibernate Fluent to work with SQLite local db.
This is how I configure 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();
}
}
When I try to build configuration I receive an exception:

I have added the following references from Nuget:
My local DB is created using SQLite Studio and database type=System.Data.SQLite.
What I am doing wrong? Maybe I am using wrong provider?
I found a solution.
Step 1 Use package [System.Data.SQLite.Core 1.0.109] in your project.
Step 2 Download package [System.Data.SQLite.Core 1.0.109.1].
Step 3 Copy [runtimes] folder which in package [System.Data.SQLite 1.0.109.1] to your project's folder with follow file mapping.
[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
Then your *.csproj file should include follow content.
<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>
Step 4 Just build and run your application.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With