views:

28

answers:

1

Hi I'm trying to map a one-many parent-child relationship in NHibernate using XML mapping. Easy enough if the parent class instances store the collection of children in a list, but I want to use a dictionary. Can anyone point me to an example that shows how to set up this mapping in XML?

In other words I want my parent class to look like this

public class Parent {

   IDictionary<string, Child> children; // key should be Child.Name

}

It's a standard primary key-foreign key relationship in the database. The Child table has Name column which should be mapped to the dictionary key.

Thanks

A: 

Child.Name can't be both a property and the dictionary key.

Diego Mijelshon
Hmm. The Child.Name field wouldn't be both a property and key in the same class. It would be a property in the Child class, and a key in the Parent class, so would only have one role in each mapping. Does that make a difference?
PhantomDrummer
I understood that. And it's still wrong. You *might* be able to make it work read-only, but it will fail when saving. Instead, you can map the children as a `<set>` and then project it client-side.
Diego Mijelshon
OK fair enough. Thanks for the response!
PhantomDrummer