marcelo-ferraz
marcelo-ferraz

Reputation: 3257

Nhibernate map multiple tables to a same list

I have multiple objects meaning various steps (each object is a step) from a flux, they are to be persisted in the DB.
I was thinking on creating a relational table, where I would have each association, only one relation per row. something like, per example:

and to clarify:

and so on...

to be referenced in the table:

How could I map this into something like:

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() { /* ... */ } 
}

Upvotes: 1

Views: 61

Answers (1)

Amir
Amir

Reputation: 639

You can use inheritence mapping like this:

<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>

For further reading: inheritance mapping

Upvotes: 1

Related Questions