FluentNHibernate SQLite默认配置ProxyFactoryFactory
我想要一个简单的单元测试配置。我的理解是sqlite fluent配置默认为Castle,我有一个NHibernate.ByteCode.Castle.dll的引用集,但是我收到一个错误,说没有ProxyFactory设置集 我错过了什么 干杯,FluentNHibernate SQLite默认配置ProxyFactoryFactory,sqlite,configuration,fluent-nhibernate,Sqlite,Configuration,Fluent Nhibernate,我想要一个简单的单元测试配置。我的理解是sqlite fluent配置默认为Castle,我有一个NHibernate.ByteCode.Castle.dll的引用集,但是我收到一个错误,说没有ProxyFactory设置集 我错过了什么 干杯, 贝里尔 ==代码=== public abstract class InMemoryDatabase : IDisposable { private static Configuration _cfg; private static I
贝里尔 ==代码===
public abstract class InMemoryDatabase : IDisposable
{
private static Configuration _cfg;
private static ISessionFactory _sessionFactory;
protected InMemoryDatabase()
{
_sessionFactory = _createSessionFactory();
Session = _sessionFactory.OpenSession();
_buildSchema(Session);
}
protected ISession Session { get; set; }
#region IDisposable Members
public void Dispose() { Session.Dispose(); }
#endregion
private static ISessionFactory _createSessionFactory()
{
return Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql())
.Mappings(M =>
M.FluentMappings.AddFromAssemblyOf<User>())
.ExposeConfiguration(Cfg => _cfg = Cfg)
.BuildSessionFactory();
}
private static void _buildSchema(ISession Session)
{
var export = new SchemaExport(_cfg);
export.Execute(true, true, false, Session.Connection, null);
}
}
MemoryDatabase中的公共抽象类:IDisposable
{
私有静态配置_cfg;
私人静态ISessionFactory_sessionFactory;
受保护的InMemoryDatabase()
{
_sessionFactory=_createSessionFactory();
会话=_sessionFactory.OpenSession();
_构建模式(会话);
}
受保护的ISession会话{get;set;}
#区域IDisposable成员
public void Dispose(){Session.Dispose();}
#端区
私有静态ISessionFactory_createSessionFactory()
{
流畅地返回。Configure()
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql())
.Mappings(M=>
M.FluentMappings.AddFromAssemblyOf())
.ExposeConfiguration(Cfg=>\u Cfg=Cfg)
.BuildSessionFactory();
}
私有静态void\u buildSchema(ISession会话)
{
var export=newschemaexport(_cfg);
export.Execute(true、true、false、Session.Connection、null);
}
}
==例外情况====
TestCase 'SmackNhibTestLab.FluentMapping.Tests.UserClassMapTests.PersistenceSpec_ok'
failed: TestFixtureSetUp failed in UserClassMapTests
TestFixture failed: FluentNHibernate.Cfg.FluentConfigurationException :
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
----> NHibernate.Bytecode.ProxyFactoryFactoryNotConfiguredException : The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
Example:
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
Example:
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
0 passed, 1 failed, 0 skipped, took 2.55 seconds (NUnit 2.5.2).
TestCase'SmackNhibTestLab.FluentMapping.Tests.UserClassMapTests.PersistenceSpec_ok'
失败:UserClassMapTests中的TestFixtureSetUp失败
TestFixture失败:FluentNHibernate.Cfg.FluentConfigurationException:
创建SessionFactory时使用了无效或不完整的配置。有关详细信息,请检查潜在原因集合和InnerException。
---->NHibernate.Bytecode.ProxyFactoryFactoryNotConfiguredException:未配置ProxyFactoryFactory。
使用可用的NHibernate.ByteCode提供程序之一初始化会话工厂配置节的“proxyfactory.factory\u类”属性。
例子:
NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu
例子:
NHibernate.ByteCode.Castle.proxyFactory,NHibernate.ByteCode.Castle
在FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()中
0通过,1失败,0跳过,耗时2.55秒(NUnit 2.5.2)。
您可以很容易地自己设置属性-请参阅下面的代码,以查看一个好方法。我仍然希望这行代码已经烘焙到SQLite默认配置中
private static ISessionFactory _createSessionFactory() {
var sqLiteConfiguration = Standard.InMemory().ShowSql();
sqLiteConfiguration.ProxyFactoryFactory(typeof(ProxyFactoryFactory).AssemblyQualifiedName); <== ** OK now
return Fluently.Configure()
.Database(sqLiteConfiguration)
.Mappings(M =>
M.FluentMappings.AddFromAssemblyOf<User>())
.ExposeConfiguration(Cfg => _cfg = Cfg)
.BuildSessionFactory();
}
私有静态ISessionFactory\u createSessionFactory(){
var sqLiteConfiguration=Standard.InMemory().ShowSql();
sqLiteConfiguration.ProxyFactoryFactory(typeof(ProxyFactoryFactory).AssemblyQualifiedName);
M.FluentMappings.AddFromAssemblyOf())
.ExposeConfiguration(Cfg=>\u Cfg=Cfg)
.BuildSessionFactory();
}
干杯,
贝里尔