当从不同的程序集调用时,会出现流畅的NHibernate配置问题



我有一个这样的项目结构:
1. NHibernate基类打开会话,数据访问功能和CRUD方法。(Dll)
2. 一种执行程序(windows窗体),它在单独的命名空间中具有域类和映射器。()
3.单元测试用例(Dll)
我使用了以下代码来创建配置:

public Configuration BuildConfig()
{
    var configuration = new Configuration();
    return Fluently.Configure(configuration)
        .Mappings(cfg => {
            cfg.FluentMappings.AddFromAssembly(Assembly.GetEntryAssembly());
        }).BuildConfiguration();
}

当我尝试从2n程序(Windows窗体应用程序)创建配置时,配置已经成功完成。

现在我已经在NUnit Test程序集中引用了上述两个程序集,并且复制了与windows窗体相同的配置设置(app.config)。流畅是无法建立会话工厂,我得到以下异常:

FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
  Database was not configured through Database method.

请帮我解决这个问题

我是一个新手;但我认为:

FluentMappings.AddFromAssembly(**Assembly.GetEntryAssembly()**); 

可能在执行winforms.exe时工作,但是在测试时将反映到执行测试的任何内容中。

也许这应该是:

FluentMappings.AddFromAssemblyOf< *mappings class* >()

或者,如果你需要使用反射:

m.FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(*mappings class* )))

最新更新