【发布时间】:2018-12-28 22:23:20
【问题描述】:
我正在 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 创建的。
我做错了什么?也许我使用了错误的提供商?
【问题讨论】:
-
为什么不是
System.Data.SQLite.Core? SQLite 程序集未部署到运行代码期望找到它们的位置。 SQLite 文档中有关于如何管理的内容吗? -
我试过了,我收到下一个警告:“警告 NU1701:使用 '.NETFramework,Version=v4.6.1' 而不是项目目标框架 '.NETCoreApp,Version=v2.0'。此包可能与您的项目不完全兼容”@DavidOsborne
-
啊。我想我已经将“核心”部分与 .Net Core 混淆了。我不认为他们是一样的。
-
我不确定 SQLite 对 .Net Core 的支持情况。扫描文档没有帮助。但是,我注意到在使用
System.Data.SQLite.Core包时,会部署SQLiteInterop.dll文件并运行代码。您需要找到一种方法将适当的 SQLite 二进制文件放入 NH 代码可以从中解析类型的位置。这是如何使用与 .Net Core 兼容的 SQLite 版本完成的,我现在不知道。
标签: c# sqlite nhibernate .net-core