构建SessionFactory时FluentNHibernate.MissingConstructorException

时间:2010-07-12 07:33:30

标签: c# fluent-nhibernate oracle9i

我正在尝试流利地配置SessionFactory来访问Oracle9i数据库,使用ODP.Net,我得到了这个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();
        }

如果有人能指出我哪里出错了,我会非常感激。

1 个答案:

答案 0 :(得分:2)

正如詹姆斯格雷戈里在他对我的问题的评论中指出的那样,在告知Fluent我的映射时,我做了一些非常愚蠢的事情。

当代码从单元测试的上下文中运用时,m => m.FluentMappings.AddFromAssembly(Assembly.GetCallingAssembly())试图告诉Fluent查看单元测试程序集中的映射 - 这将是失败的,很糟糕。

答案是使用m => m.FluentMappings.AddFromAssemblyOf<Foo>(),其中Foo是程序集中的类型是映射。