NHibernate:将一个类映射到两个相同的表 [英] NHibernate: Map one class to two identical tables

查看:101
本文介绍了NHibernate:将一个类映射到两个相同的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一个实体映射到两个表(发票和发票历史)。这不合我的两个数据库表合并,并添加一个状态列来区分它们。

这两张表具有完全相同的结构,但正如名称所示,InvoiceHistory保留旧发票的历史记录,而发票存储活动发票。 (确切的实体是不是发票,但我不能透露细节,我不认为他们将是相关的反正)。

解决方案

创建另一个继承你创建的第一个实体的实体,除此之外别无其他。然后您可以将新实体映射到InvoiceHistory,而第一个仍映射到发票。

I need to map one entity to two tables (Invoice and InvoiceHistory). It's not up to me to merge the two database tables in one and add a status column to differentiate them.

The two tables have the exact same structure, but, as the name says, InvoiceHistory keeps a history of old invoices whereas Invoice stores active invoices. (the exact entity is not invoice but I am not allowed to disclose details plus I don't think they would be relevant anyway).

解决方案

Create another entity which inherits the first entity you created and does nothing else. You can then map the new entity to InvoiceHistory, while the first one is still mapped to Invoice.

这篇关于NHibernate:将一个类映射到两个相同的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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