构建 SessionFactory 时出现 FluentNHibernate.MissingConstructorException

发布于 2024-09-09 09:38:40 字数 2602 浏览 3 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟─花易冷 2024-09-16 09:38:40

正如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文