在数据库中实现子类化

编程入门 行业动态 更新时间:2024-10-26 16:24:02
本文介绍了在数据库中实现子类化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

在数据库中实现子类化

本文发布于:2023-10-18 12:23:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子类   数据库中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!