【问题标题】:Nhibernate map multiple tables to a same listNhibernate 将多个表映射到同一个列表
【发布时间】:2014-06-07 06:27:24
【问题描述】:

我有多个对象,表示来自通量的各个步骤(每个对象都是一个步骤),它们将被持久保存在数据库中。
我正在考虑创建一个关系表,其中我将拥有每个关联,每行只有一个关系。例如:

  • 步骤:Id、Course_Id、Evaluation_Id、ProcessEvaluation_Id

并澄清:

  • StepsForClass:id、class_id、steps_id
  • 课程:id, someMoreinfo
  • 评估:id、someOtherinfo

等等……

表中引用:

  • :Id、StepsForClass_id、someInfo

我怎么能把它映射成类似的东西:

public class Klass
{
   public uint Id { get; set; }
   public IList<Step> Steps { get; set; }
}

public abstract class Step
{
   public uint Id { get; set; }
   public abstract void Apply();
}

public class Course : Step
{
   //( some more fields )
   public override void Apply() { /* ... */ } 
}


public class Evaluation : Step
{
   //( some other more fields )
   public override void Apply() { /* ... */ } 
}

【问题讨论】:

    标签: mysql sql nhibernate mapping nhibernate-mapping


    【解决方案1】:

    您可以像这样使用继承映射:

    <class name="Step" table="STEP">
        <id name="Id" type="Int64" column="STEP_ID">
            <generator class="native"/>
        </id>
        <property name="Amount" column="AMOUNT"/>
        ...
        <joined-subclass name="Course" table="COURSE">
            <key column="STEP_ID"/>
            ...
        </joined-subclass>
        <joined-subclass name="Evaluation" table="EVALUATION">
            <key column="STEP_ID"/>
            ...
        </joined-subclass>
    </class>
    

    进一步阅读:inheritance mapping

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 2012-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多