NHibernate映射与分叉继承模型 [英] NHibernate mapping with forking inheritance model
问题描述
我只是从NHibernate开始,正在尝试为我的模型进行映射. (这是一种模型优先的TDD方法,现在就创建数据库)
I'm just starting out with NHibernate and am trying to do a mapping for my model. (this is a model-first, TDD approach, just creating the database now)
我的班级等级类似:
我正在尝试找出如何现在使用映射xml文件对此进行映射?
I'm trying to work out how to map this now using a mapping xml file?
这是我的桌子,我想让他们映射到
This is my table and what I want them to map to
QuestionId-整数-[Question.Id]
QuestionId - Int - [Question.Id]
PmqccFormId-整数-[Question.PmqccForm.Id]
PmqccFormId - Int - [Question.PmqccForm.Id]
InputAnswer-Int-[NormalQuestion.InputtedAnswer或JobVelocityQuestion.InputtedAnswer -它们都是将转换为int或从int转换的枚举,可以根据需要将它们分成单独的列]
InputtedAnswer - Int - [NormalQuestion.InputtedAnswer or JobVelocityQuestion.InputtedAnswer - they are both enums that will be converted to/from ints, can separate these into separate columns if need be]
ResponsibleStaffId -Int-[PiAlertQuestion.ResponsibleStaffMember.Id]
ResponsibleStaffId -Int - [PiAlertQuestion.ResponsibleStaffMember.Id]
说明-varchar-[Question.Explanation]
Explanation - varchar - [Question.Explanation]
QuestionType-varchar-[Discriminator]
QuestionType - varchar - [Discriminator]
我不确定如何映射它,因为它有点分叉.还有更多的"Question"对象,它们都从YesNoQuestion或NormalQuestion继承,但不再添加属性,仅添加方法实现.
I'm not sure how to map this given it forks a a bit. There are a heap more 'Question' objects that all inherit from YesNoQuestion or NormalQuestion but don't add anymore properties, just methods implementations.
我猜我对Question基类有一个,然后在那个基类下有一个?棘手的是JobVelocityQuestion从Question继承.谁能指出我正确的方向?
I'm guessing I have a for the Question base class and then have ones under that? the tricky bit is the JobVelocityQuestion inheriting from Question. Can anyone point me in the right direction?
推荐答案
这应该使您入门:
<class name="Question">
...
<discriminator column="QuestionType"/>
<subclass name="JobVelocityQuestion">
<property name="InputtedAnswer"/>
</subclass>
<subclass name="NormalQuestion">
<property name="InputtedAnswer"/>
<subclass name="AsConsQuestion"/>
...
</subclass>
我做了很多假设,但是应该可以.随时提出进一步的要求.
I made many assumptions, but it should work. Feel free to ask further.
这篇关于NHibernate映射与分叉继承模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!