具有隐式多态性的每个混凝土表的实际用途是什么? [英] Any real use for table-per-concrete-class with implicit polymorphism?

查看:56
本文介绍了具有隐式多态性的每个混凝土表的实际用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用每个具体类的表映射继承,而映射具体类的方式与其他任何类一样简单(没有union-subclass),则NHibernate允许跨子类使用相同的PK.例如,如果您有BillingDetails以及CreditCard和BankAccount子类,则请求所有BillingDetails将从两个表中获取所有记录,这些表又可能具有重复的主键,由于这些对象的业务标识无效,因此可能会出现问题.当然,这种情况并非如此,但是普通身份或序列ID生成器的情况又如何呢?

If mapping inheritance using table per concrete class, while mapping concrete classes simply just as any other class (without union-subclass), NHibernate allows same PKs across subclasses. For example if you have BillingDetails and subclasses CreditCard and BankAccount, requesting all BillingDetails will get you all records from both tables, which can in turn have duplicate primary keys, which can be problematic due to not valid business identity of those objects. This of course is not the case with guids and such, but what about cases of plain identity or sequence id generators?

简单来说,问题是,当请求这样的多态查询时,重复id密钥的此方案是否有实际用途?在内部处理实体时,这些重复的ID会给NHibernate带来麻烦吗?

Simply, the question is, is there any real use of this scenarion of duplicate id keys when requesting polymorphic query like that? Could these duplicate ids make problems for NHibernate when handling entities internally?

推荐答案

在映射表不共享公共键的旧模型时,隐式多态性是必需的.

Implicit polymorphism is necessary when mapping legacy models where the tables do not share a common key.

使用共享相同ID的CreditCard和BankAccount实例获取BillingDetails列表是没有问题的,因为NH知道它们是不相关的(并且仅出于查询目的,通过对每个映射运行一个查询,它们被视为相关.子类)

There are no problems with getting a list of BillingDetails with CreditCard and BankAccount instances sharing the same Id, because NH knows they are unrelated (and they are treated as related only for the purposes of querying, by running one query for each mapped subclass)

您不应将其用于未开发的领域.

You should not use it for greenfield development.

这篇关于具有隐式多态性的每个混凝土表的实际用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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