gpt4 book ai didi

nhibernate - SQLite NHibernate 配置与 .Net 4.0 和 vs 2010

转载 作者:行者123 更新时间:2023-12-03 16:16:06 25 4
gpt4 key购买 nike

我正在用我认为我现在知道的关于获取此配置的信息更新这篇文章;但是,还有更多需要了解,因为我仍然遇到问题是一个关键领域。

我使用 SQLite 进行单元测试,现在工作正常,使用以下配置步骤。当我想要测试运行的 UI 的数据多于内存测试数据但没有 SQLServer 的开销时,我也会使用它 - 此配置失败并出现以下情况:

{"Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4."}

以下是有关可以工作的配置的更新信息:

1)哪个SQLite dll?有一些不好的链接看起来很有帮助,但其中存在构建错误。截至目前,唯一好的下载是 here at Source Forge . v1.066 今天发布,2010 年 4 月 18 日。

2) 您必须使用 GAC 吗?不,正如毛里西奥所回答的那样。

3) x64 构建 - 正如 Mauricio 所回答。

4) NHib 驱动程序 - SQLite20Driver,由 Mauricio 回答

5) FNH 作为潜在冲突 - 不,正如 Mauricio 所回答的那样

干杯,
贝瑞尔

== 添加调试信息 ===

当遇到异常并且我调用 SQLite20Drive 程序集时,我得到以下信息,这表明驱动程序应该可用。我想知道,因为配置代码在不同的程序集中。

-- 错误时组装 ----
    ?typeof(SQLite20Driver).Assembly
{NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
[System.Reflection.RuntimeAssembly]: {NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
CodeBase: "file:///C:/Users/Lord & Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.WpfPresentation/bin/Debug/NHibernate.DLL"
EntryPoint: null
EscapedCodeBase: "file:///C:/Users/Lord%20%26%20Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.WpfPresentation/bin/Debug/NHibernate.DLL"
Evidence: {System.Security.Policy.Evidence}
FullName: "NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4"
GlobalAssemblyCache: false
HostContext: 0
ImageRuntimeVersion: "v2.0.50727"
IsDynamic: false
IsFullyTrusted: true
Location: "C:\\Users\\Lord & Master\\Documents\\Projects\\Smack\\trunk\\src\\ConstructionAdmin.WpfPresentation\\bin\\Debug\\NHibernate.dll"
ManifestModule: {NHibernate.dll}
PermissionSet: {<PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>
}
ReflectionOnly: false
SecurityRuleSet: Level1

--- 单元测试时的组装(无错误)
{NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
[System.Reflection.RuntimeAssembly]: {NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
CodeBase: "file:///C:/Users/Lord & Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.Tests/bin/Debug/NHibernate.DLL"
EntryPoint: null
EscapedCodeBase: "file:///C:/Users/Lord%20%26%20Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.Tests/bin/Debug/NHibernate.DLL"
Evidence: {System.Security.Policy.Evidence}
FullName: "NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4"
GlobalAssemblyCache: false
HostContext: 0
ImageRuntimeVersion: "v2.0.50727"
IsDynamic: false
IsFullyTrusted: true
Location: "C:\\Users\\Lord & Master\\Documents\\Projects\\Smack\\trunk\\src\\ConstructionAdmin.Tests\\bin\\Debug\\NHibernate.dll"
ManifestModule: {NHibernate.dll}
PermissionSet: {<PermissionSet class="System.Security.PermissionSet"

版本=“1”
无限制=“真”/>
}
仅反射:假
安全规则集:Level1

这是此 SQLite session 的 bootstrap :
    /// <summary>SQLite-NHibernate bootstrapper for general use.</summary>
public class SQLiteBoot : IDisposable
{
public readonly ISessionFactory SessionFactory;
private readonly ISession _session;
private static Configuration _config;
private static string _persistenceModelGeneratorName;

public SQLiteBoot(IAutoPersistenceModelGenerator persistenceModelGenerator) {
if (_isSessionFactoryBuildRequired(persistenceModelGenerator)) {
_config = new Configuration()
.SetProperty(ENV.ReleaseConnections, "on_close")
.SetProperty(ENV.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName)
.SetProperty(ENV.ConnectionDriver, typeof (SQLite20Driver).AssemblyQualifiedName)
.SetProperty(ENV.ConnectionString, "data source=:memory:")
.SetProperty(ENV.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName)
.SetProperty(ENV.CurrentSessionContextClass, typeof (ThreadStaticSessionContext).AssemblyQualifiedName);

_persistenceModelGeneratorName = persistenceModelGenerator.Name;
var persistenceModel = persistenceModelGenerator.Generate();
var fluentCfg = Fluently.Configure(_config).Mappings(m => m.AutoMappings.Add(persistenceModel));
SessionFactory = fluentCfg.BuildSessionFactory();
Check.Require(SessionFactory.GetAllClassMetadata().Count > 0, "No mapped classes - check your AutoPersistenceModel!");

}

_session = SessionFactory.OpenSession();
CurrentSessionContext.Bind(_session);

new SchemaExport(_config).Execute(true, true, false, _session.Connection, Console.Out);
}

private bool _isSessionFactoryBuildRequired(IAutoPersistenceModelGenerator persistenceModelGenerator)
{
return
_config == null
|| SessionFactory == null
|| !persistenceModelGenerator.Name.Equals(_persistenceModelGeneratorName);
}

public void Dispose()
{
_session.Dispose();
}
}

}

最佳答案

  • 当然。如果您配置 mixed mode loading,您也可以使用以前的版本.
  • 无需加入 GAC。您可以使用 gacutil 从 GAC 中删除程序集。
  • 使用 x64 DLL 将 Windows x64 和 x86 定位到 Windows x86
  • 请发布完整的异常堆栈跟踪。此外,如果您使用的是 3.5 程序集,请使用 mixed mode loading .
  • FNH 没有提及 SQLite。
  • 关于nhibernate - SQLite NHibernate 配置与 .Net 4.0 和 vs 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2649194/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com