在数据库中实现子类化 [英] Implementing Subclassing in the Database

查看:81
本文介绍了在数据库中实现子类化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序将具有一个父类,该父类将具有许多基本字段和方法,以及几个带有附加字段方法的子类.

I'm developing an application that will have a parent class which will have many basic fields and methods, and several subclasses with additional fields methods.

好奇如何最好地在数据库中实现.为父类提供一个表,为子类提供一个单独的表并通过id字段链接它们是否有意义,还是为了方便访问和简化查询而在子类表中复制父类的字段更好? >

Curious how best to implement in the database. Does it make sense to have one table for the parent class, a separate table for the subclass and link them via id fields, or is it better to duplicate the parent class fields in the subclass tables for ease of access and simpler querying?

推荐答案

您的问题的答案是肯定的,它们都是有效的方法.它取决于诸如查询某些内容时要执行的联接数以及是否要支持多态查询之类的事情. 这是Scott Ambler撰写的有关该主题的文章.文章的2.6节中有一个漂亮的表格,列出了不同映射方法的优缺点.

The answer to your question is yes, those are both valid approaches. It depends on things like how many joins you want done when you query something, and whether you want polymorphic queries to be supported. Here's an article on the subject by Scott Ambler. Section 2.6 in the article has a nice table that lists advantages and disadvantages of different mapping approaches.

这篇关于在数据库中实现子类化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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