与NHibernate在多个数据库填充对象 [英] Populating objects with NHibernate across multiple databases

查看:248
本文介绍了与NHibernate在多个数据库填充对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个数据库的一条SQL服务器。数据库1具有到ID的参照存储在上的Database2一个表的表。不知道是否是可能的,但我可以配置NHibernate的(流利NHibernate的专门)饱和对象从多个数据库中提取数据?

I have one SQL Server with multiple databases. Database1 has a table with a reference to IDs that are stored in a table on Database2. Not sure if it's possible, but could I configure NHibernate (Fluent NHibernate specifically) to saturate an object pulling data from multiple databases?

我不关心写入这些表,我只是想在ORM的数据查看应用程序中显示的对象。

I'm not concerned about writing to these tables, I'm just trying to ORM the objects to display in an data viewing application.

我知道这不是一个理想的数据库的情况,但它是我是什么给出的工作。

I realize this isn't an ideal database situation, but it's what I was given to work with.

推荐答案

通常的答案具体的DB-查询结构,比如跨数据库的查询,是创建一个视图本地数据库(即NH连接)将执行跨数据库查询并返回连接结果。你也可以有一个存储库每DB和开发一些手段来查询每个数据库的记录,并手动将其加入

The usual answer to db-specific query structures, like cross-DB queries, is to create a view on the "local" DB (that NH connects to) that will perform the cross-DB query and return the joined results. You can also have a repository-per-DB and develop some means to query the records from each DB and join them manually.

一件事,也将工作;每个映射的表属性只是一个字符串,可以是任何东西; NHibernate的只是需要这一点,它插入无论它需要引用的表名。所以,你可以尝试使用他们的完全限定名称指定的映射表:ConnectedDB..LocalTable,OtherDB..RemoteTable。这可能被认为是一个黑客,但它也是在某种程度上相当优雅;你的程序甚至不需要知道有在持久性方案多个数据库。

One thing that will also work; the table property of each mapping is just a string, and could be anything; NHibernate just takes that and plugs it in wherever it needs to reference the table name. So, you could try specifying the tables in the mappings using their fully-qualified names: ConnectedDB..LocalTable, OtherDB..RemoteTable. It might be considered a hack, but it's also rather elegant in a way; your program doesn't even have to know there are multiple databases in the persistence schema.

这篇关于与NHibernate在多个数据库填充对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆