SQLite NHibernate 配置与 .Net 4.0 和 vs 2010
我正在用我认为我现在知道的关于获取此配置的信息更新这篇文章;但是,还有更多需要了解,因为我仍然遇到问题是一个关键领域.
I am updating this post with what I think I now know about getting this configuration; HOWEVER, there is more to know as I am still having a problem is one crucial area.
我使用 SQLite 进行单元测试,现在工作正常,使用以下配置步骤.当我希望使用比内存中测试数据更多的数据但没有 SQLServer 开销的 UI 测试运行时,我也会使用它 - 此配置失败并显示以下内容:
I use SQLite for unit testing, which now works fine, using the configuration steps below. I also use it when I want a test run of the UI with more data than in-memory test data but without the overhead of SQLServer - this configuration fails with the following:
{"Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4."}
这里是关于可以工作的配置的更新信息:
Here is updated info on configs that DO work:
1) 哪个 SQLite dll?有一些错误的链接看起来很有帮助,但其中存在构建错误.截至目前,唯一好的下载是此处位于 Source Forge.v1.066,今天发布,2010 年 4 月 18 日.
1) Which SQLite dll?? There are some bad links out there that look helpful but that have build errors in them. The only good download as of this date is here at Source Forge. v1.066 which was released today, 4-18-2010.
2) 您必须使用 GAC 吗?不,正如 Mauricio 的回答.
2) Must you use the GAC? No, as answered by Mauricio.
3) x64 构建 - 正如 Mauricio 所回答的那样.
3) x64 builds - as answered by Mauricio.
4) NHib 驱动程序 - SQLite20Driver,由 Mauricio 回答
4) NHib driver - SQLite20Driver, as answered by Mauricio
5) FNH 作为潜在冲突 - 不,正如 Mauricio 的回答
5) FNH as a potential conflict - no, as answered by Mauricio
干杯,
贝瑞尔
== 添加调试信息 ===
== ADD'L DEBUG INFO ===
当遇到异常并且我调用 SQLite20Drive 程序集时,我得到以下提示,提示我驱动程序应该可用.我想知道,因为配置代码在不同的程序集中.
When the exception is hit and I call up the SQLite20Drive assembly, I get the following which suggests to me that the driver should be available. I am wondering though, as the configuration code is in a different assembly.
-- 出现错误时的汇编 ----
-- assembly when error ----
?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
--- 单元测试时的汇编(无错误)
--- assembly when unit testing (NO ERROR)
{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
version="1" Unrestricted="true"/> } ReflectionOnly: false SecurityRuleSet: Level1
这是此 SQLite 会话的引导程序:
Here is the bootstrapper for this a SQLite session:
/// <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();
}
}
}
推荐答案
我希望这能脱颖而出,以便对其他人有所帮助;发生这种情况的全部原因在此处进行了解释;因此,请调整您的配置以将那里的重定向与 Mauricio 此处引用的混合加载模式结合使用.
I want this to stand out so it will help someone else; the full reason this happens is explained here; so adjust your congig to use BOTH the redirect there in combo with the mixed loading mode referenced here by Mauricio.
相关文章