0

I am new to NHibernate and am running into some issues with mapping.

Lets say I have a table:

People PersonID PersonName PersonAge 

Then I have another table

ParentRelaitions RelationID Parent (This is a PersonID) Child (This is also a PersonID) 

What I really want to get out of this is an object like this

public class Person { string name; int age; IList<Person> Children; //This is a list of all the persons children } 

How would I go about setting this up? I am fairly lost and can't seem to find any relevant examples.

Thanks

1
  • For what do you use the relationId? Commented Aug 24, 2010 at 20:23

3 Answers 3

3

This should get you started:

<class name="Person"> <id column"PersonId" type="..."> <generator class="..."/> </id> <property name="name" column="PersonName" access="field"/> <property name="age" column="PersonAge" access="field"/> <idbag name="Children" table="ParentRelations"> <collection-id column="RelationId" type="..."> <generator class="..."/> </collection-id> <key column="Parent"/> <many-to-many column="Child" class="Person"/> </idbag> </class> 
Sign up to request clarification or add additional context in comments.

Comments

1

I do not understand. What is the relationship between Parent and child? 1:N or M:N? If 1:N then study NHibernate relation many-to-one, if M:N then study many-to-many.

1 Comment

Yep, looks like a many-to-many. It just happens that it's the same table on both sides of the relationship.
0

Your example is a bit vague, but you should look into using an Association Class.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.