我正在开发一个应用程序,该应用程序将具有一个父类,该父类将具有许多基本字段和方法,以及几个带有附加字段方法的子类.
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.
更多推荐
在数据库中实现子类化
发布评论