NHibernate:在不同服务器上的多个数据库之间映射实体,无需数据库链接
使用最新版本的NHibernate(可能还有一些插件),是否可以在不使用数据库链接的情况下在不同服务器上的多个数据库之间映射实体?
对于背景,我希望实现与DBA中描述的内容大致相似的东西.SE帖子。
Using the latest version of NHibernate (and possibly some plugins), is that possible to map entities across multiple databases on different servers without DB link?
For the background, I'm looking to implement something loosely similar to what is described in this DBA.SE post.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在以下问题上得到了有趣的答案 nhusers 邮件列表。摘录如下:
I've got an interesting answer on the nhusers mailing list. Excerpt follows:
经过一些谷歌搜索(虽然我还没有尝试过),您显然至少可以使用
映射将类映射到同一服务器上不同数据库中的表。
但恕我直言,这是一个蹩脚的解决方案,因为它似乎并不独立于服务器。显然,NHibernate 只是在创建查询时将模式值与表值连接起来 - 对于大多数服务器来说,“只需将数据库与模式放在一起”就会产生一种语法,这种语法会起作用。但是你并没有清楚地告诉NHibernate“这是模式”和“这是数据库”,以便NHibernate可以清楚地决定如何构建查询——你通过在不属于的地方注入上下文数据来搞乱它的查询创建。
恕我直言,NHibernate 应该抑制这种肮脏的黑客行为,并在“schema”值包含 .
无论如何,似乎没有技术原因说明您不能更进一步并使用 schema="server.database.schema",其中“server”是链接服务器的名称(例如,请参见 http://technet.microsoft.com/de-de/library/ms190479.aspx )
除了那个肮脏的黑客之外,每个人似乎都建议使用多个会话工厂。
After some googeling (although I haven't tried this yet), you can apparently at least map classes to tables in different databases on the same server, using
in the mapping.
But IMHO this is a crappy solution, because it doesn't seem to be server-independent. Apparently, NHibernate just concatenates the schema value with the table value in the creation of the query - and for most servers, "just putting the database in there with the schema" results in a syntax, which HAPPENS work. BUT you don't cleanly tell NHibernate "this is the schema" and "this is the database" so that NHibernate can cleanly decide how to build the query - you mess with its query creation by injecting contextual data where it doesn't belong.
IMHO, NHibernate should suppress such dirty hacks and throw an exception if the "schema" value contains a .
Anyhow, there seems to be no technical reason why you shouldn't be able to go one step further and use schema="server.database.schema", where "server" is a name of a linked server (see for example http://technet.microsoft.com/de-de/library/ms190479.aspx )
Apart from that dirty hack, everyone seems to recommend using multiple session factories.