views:

236

answers:

1

We have a situation where we want to define a relationship where a class (named Module) may or may not be related to a Module object that is a predecessor to it. There can be zero or none predecessors. The class looks like this:

public class Module
{
    public int Id
    {
        get;
        set;
    }

    // other stuff here

    public Module Predecessor
    {
        get;
        set;
    }
}

And we have defined our mapping so that Predecessor is a property of type Module like so:

<class name="Module">
    <Id name="Id">
        <generator class="native/>
    </Id
    <property name="Predecessor" type="Module" "unique="true"/>
<class>

However we are getting complaints about the mapping not being able to compile because it cannot find the type "Module". We have tried the long name for the class

type="STC.EI.JobSubmissionSystem.Data.Domain"

and the fully-qualified name for the class

type="STC.EI.JobSubmissionSystem.Data.Domain, STC.EI.JobSubmissionSystem.Data"

to no avail. My question is:

Are we mapping this properly, and if not then how do we map it properly?

+2  A: 

You could use the many-to-one element:

<class name="Module">
    <Id name="Id">
        <generator class="native"/>
    </Id>
    <many-to-one name="Predecessor" class="Module" column="predecessor_id" />
<class>

Note that you need a column in your table to define the relation.

Darin Dimitrov
This is correct. I just wanted to add that the reason it doesn't compile is that you can't specify domain classes in a 'type' attribute; you have to use one of the elements that support the 'class' attribute (like many-to-one).
Stuart Childs
@darin - Ahh, thanks for the info, this solution worked!@Stuart - helpful tip, thank you! We were getting a lot of errors that it couldn't find the type with the original mapping
Jeffrey Cameron