首页 文章

NHibernate多个数据库提供者

提问于
浏览
4

我有一个在客户端上运行的WPF应用程序 . 我有两个应用程序使用的不同数据库 . 一个是用于应用程序数据的SQL Server 2008,另一个是用于存储在客户端上的用户设置的Sql Server Compact . 我正在使用app.config来配置NHibernate . 我在类映射文件中看过很多使用“schema”属性的文章,但这只有在我连接到同一个SQL Server时才有效 . 如何配置NHibernate以设置两个不同的会话工厂?

我想在app.config文件中配置它,如果可能的话 .

3 回答

  • 5

    在我将所有内容转换为使用Fluent NHibernate和依赖注入之前,我的公司's NH libraries were configured to use multiple database and it was configurable through app.config (well, web.config in this case). I believe it was using a session manager based off the one in Bill McCafferty' s CodeProject article .

    如果你不需要一些复杂的东西,它在很大程度上是一个有用的包装器:

    Configuration cfg = new Configuration();
    cfg.Configure(sessionFactoryConfigPath);
    sessionFactory = cfg.BuildSessionFactory();
    

    您可以使用上面的方法创建自己的方法来传递会话工厂配置文件并实例化会话工厂 .

  • 0

    您可能还想看看这个答案 . 它完全按照您在问题中描述的方式执行 . Configure NHibernate hibernate.cfg.xml file to have more connection strings

相关问题