自动映射不同的dll到不同的数据库
我最近开始使用 nhibernate 3 和 Fluent nhibernate 作为我的 ORM 在家里构建一个域。我的域中的一切都有效。
我目前想探索使用 automapper 将解决方案中的不同 dll 映射到不同数据库的可能性。我的谷歌功夫发现与我的“研究”很少且不相关的结果。
能做到吗?如果这样做,我的 IQueryables 会发生什么情况,其中我的查询可以包含来自不同数据库的实体,而这些数据库不一定由同一数据库实例或物理机托管?
例如,我想做(连接字符串不同):
connectionstring1: Data Source=myTestServerAddress;Initial Catalog=test;User Id=myTestUsername;Password=myTestPassword;
namespace test //in assembly test, connectionstring1
{
public class test
{
public virtual int Id { get; set; }
public virtual string testme { get; set; }
}
}
连接字符串2:数据源=myTestTestServerAddress;初始目录=TestTest;用户ID=myTestTestUsername;密码=myTestTestPassword;
namespace testtest //in assembly testtest, connectionstring2
{
public class testtest
{
public virtual int Id { get; set; }
public virtual test test { get; set; } //test is in different assembly
}
}
I recently started building a domain at home using nhibernate 3 and fluent nhibernate as my ORM. Everything in my domain works.
I am currently wanting to explore the possibility of using automapper to map different dlls in my solution to different databases. My google-kung-fu is finding little and non-related results with my "research".
Can it be done? If it were to be done, what would happen to my IQueryables where my query can contain entities that come from different databases that are not necessarily hosted by the same database instance or physical machine?
for example, I am wanting to do (the connection strings are different):
connectionstring1: Data Source=myTestServerAddress;Initial Catalog=test;User Id=myTestUsername;Password=myTestPassword;
namespace test //in assembly test, connectionstring1
{
public class test
{
public virtual int Id { get; set; }
public virtual string testme { get; set; }
}
}
connectionstring2: Data Source=myTestTestServerAddress;Initial Catalog=TestTest;User Id=myTestTestUsername;Password=myTestTestPassword;
namespace testtest //in assembly testtest, connectionstring2
{
public class testtest
{
public virtual int Id { get; set; }
public virtual test test { get; set; } //test is in different assembly
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定为什么你希望它们驻留在不同的数据库中。您可以使用分片来负载平衡或(如 Cole W 所说)仅保存 testtest 中的 test_id 使用 2 个不同的 sessionfactories 并从第一个会话打开一个会话以在需要时进行测试。
I'm not sure why you want them to reside in different databases. You can use sharding to loadbalance or (like Cole W said) save only the test_id in testtest use 2 different sessionfactories and open a session from the first to get test when needed.