使用 Fluent NHibernate & 映射两个数据库之间的属性S#arp 架构
我有一个场景,我有一个使用 NHibernate 和 S#arp 架构构建的新应用程序。该应用程序正在集成到不使用 NHibernate 的旧应用程序中。旧应用程序和新应用程序将有单独的数据库。我能够使用两个 S#arp Niberate 工厂密钥成功从两个数据库中读取对象(如详细信息)。这一切都很好。我的问题是当我想要将新应用程序中的类的属性映射到旧数据库中的对象时。考虑以下场景:
public class NewUser
{
public virtual LegacyUser LegacyUser { get; set; }
}
public class LegacyUser
{
public virtual string UserName { get; set; }
}
我可以读取 NewUser 对象,但是当我尝试引用 LegacyUser 属性时,出现错误:
System.Data.SqlClient.SqlException: Invalid object name 'NewSchema.LegacyUser'.
我怀疑发生这种情况是因为检索 NewUser 对象的会话不知道有关该会话的任何信息需要读取旧的用户对象。会话工厂密钥通常由 S#arp 存储库指定。
我尝试在映射中指定架构,但这也不起作用。
mapping.Schema("OldSchema");
问题:是否有任何方法可以在 Fluent NHibernate 映射中指定当 NewUser 对象尝试读取 LegacyUser 对象时它需要使用不同的会话工厂?或者我是否必须手动从旧数据库中读取对象并将它们插入到我的新类中?
提前致谢!
I have a scenario where I have a new application built using NHibernate and S#arp Architecture. This application is being integrated into a legacy application that does not use NHibernate. There will be separate databases for the legacy and new applications. I am able to successfully read objects from both databases using two S#arp NHiberate factory keys (as detailed here). This all works great. My problem is when I want to map a property from a class in my new application to an object in the legacy database. Consider the following scenario:
public class NewUser
{
public virtual LegacyUser LegacyUser { get; set; }
}
public class LegacyUser
{
public virtual string UserName { get; set; }
}
I can read my NewUser objects, but when I attempt to reference the LegacyUser property I get an error:
System.Data.SqlClient.SqlException: Invalid object name 'NewSchema.LegacyUser'.
I suspect this is happening because the session that is retrieving the NewUser objects doesn’t know anything about the session that is required to read the old user objects. The session factory key is usually specified by the S#arp repository.
I've tried specifying the schema in the mapping, but this doesn't work either.
mapping.Schema("OldSchema");
Question: Is there any way to specify in the Fluent NHibernate mapping that when the NewUser object attempts to read the LegacyUser object it needs to use a different session factory? Or do I have to manually read the objects from the legacy database and insert them into my new classes?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论