构建 SessionFactory 时出现 FluentNHibernate.MissingConstructorException
我正在尝试使用 ODP.Net 流畅地配置 SessionFactory 以访问 Oracle9i 数据库,但我收到了 MissingConstructorException。我已经正确地整理了实际的流畅映射,但我不确定我还做错了什么。
这是例外:
BasicConnectionTests.AssertThatWeCanConnectToADatabase :
FailedFluentNHibernate.MissingConstructorException: 'FluentNHibernate.Automapping.IAutoClasslike, FluentNHibernate, Version=1.1.0.685, Culture=neutral, PublicKeyToken=8aa435e3cb308880' is missing a parameterless constructor.
at FluentNHibernate.Utils.Extensions.InstantiateUsingParameterlessConstructor(Type type)
at FluentNHibernate.PersistenceModel.Add(Type type)
at FluentNHibernate.Utils.CollectionExtensions.Each<T>(IEnumerable`1 enumerable, Action`1 each)
at FluentNHibernate.PersistenceModel.AddMappingsFromSource(ITypeSource source)
at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at MyAwesomeApp.sessionFactories.Oracle9SessionFactoryWrapper.Configure(String userName, String passWord, String dataBase) in Oracle9SessionFactoryWrapper.cs: line 26
at MyAwesomeApp.Tests.oracle.BasicConnectionTests.AssertThatWeCanConnectToADatabase() in BasicConnectionTests.cs: line 17
这是流畅的映射:
public ISessionFactory Configure(string userName, string passWord, string dataBase)
{
var config = Fluently.Configure();
config.Database(
OracleDataClientConfiguration.Oracle9
.ConnectionString(cs => cs.Username(userName).Password(passWord).Instance(dataBase))
.Driver("NHibernate.Driver.OracleDataClientDriver")
#if DEBUG
.ShowSql()
#endif
);
config.Mappings(
m => m.FluentMappings.AddFromAssembly(Assembly.GetCallingAssembly()));
return config.BuildSessionFactory();
}
如果有人能指出我哪里出错了,我将不胜感激。
I'm trying to fluently configure a SessionFactory to access an Oracle9i database, using ODP.Net, and I'm getting this MissingConstructorException. I've got the actual fluent mappings sorted out ok, but I'm not sure what else it is that I've done wrong.
Here is the exception:
BasicConnectionTests.AssertThatWeCanConnectToADatabase :
FailedFluentNHibernate.MissingConstructorException: 'FluentNHibernate.Automapping.IAutoClasslike, FluentNHibernate, Version=1.1.0.685, Culture=neutral, PublicKeyToken=8aa435e3cb308880' is missing a parameterless constructor.
at FluentNHibernate.Utils.Extensions.InstantiateUsingParameterlessConstructor(Type type)
at FluentNHibernate.PersistenceModel.Add(Type type)
at FluentNHibernate.Utils.CollectionExtensions.Each<T>(IEnumerable`1 enumerable, Action`1 each)
at FluentNHibernate.PersistenceModel.AddMappingsFromSource(ITypeSource source)
at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at MyAwesomeApp.sessionFactories.Oracle9SessionFactoryWrapper.Configure(String userName, String passWord, String dataBase) in Oracle9SessionFactoryWrapper.cs: line 26
at MyAwesomeApp.Tests.oracle.BasicConnectionTests.AssertThatWeCanConnectToADatabase() in BasicConnectionTests.cs: line 17
Here is the fluent mapping:
public ISessionFactory Configure(string userName, string passWord, string dataBase)
{
var config = Fluently.Configure();
config.Database(
OracleDataClientConfiguration.Oracle9
.ConnectionString(cs => cs.Username(userName).Password(passWord).Instance(dataBase))
.Driver("NHibernate.Driver.OracleDataClientDriver")
#if DEBUG
.ShowSql()
#endif
);
config.Mappings(
m => m.FluentMappings.AddFromAssembly(Assembly.GetCallingAssembly()));
return config.BuildSessionFactory();
}
If anyone can point out where I'm going wrong, I'd be most grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 James Gregory 在对我的问题的评论中指出的那样,当我告诉 Fluent 我的映射是什么时,我做了一些非常愚蠢的事情。
当从单元测试的上下文中执行代码时,
m => m.FluentMappings.AddFromAssembly(Assembly.GetCallingAssembly())
试图告诉 Fluent 在单元测试程序集中查找映射 - 这将会失败,非常糟糕。答案是使用
m =>; m.FluentMappings.AddFromAssemblyOf()
,其中 Foo 是映射所在程序集中的类型。As James Gregory pointed in his comment on my question, I was doing something really stupid when informing Fluent were my mappings were.
When the code was exercised from the context of a unit test,
m => m.FluentMappings.AddFromAssembly(Assembly.GetCallingAssembly())
tried to tell Fluent to look in the unit test assembly for the mappings - which is going to fail, miserably.The answer is to use
m => m.FluentMappings.AddFromAssemblyOf<Foo>()
, where Foo is a type in the assembly were the mappings are.