views:

15

answers:

1

Hi,

This is probably a very simple question but I'm new to nHibernate and I'm having trouble working this out.

I have a Page object, which can have many Region objects. I also have a Workflow object. Page and Region objects both have a relationship to Workflow and it's this double association that I'm having trouble with.

The PageMap has

HasMany(Function(x) x.Regions).Cascade.All()

And the RegionMap has:

 References(Function(x) x.Page)

And this all seems to work.

But how do I define the relationship between Workflow and these two objects?

+1  A: 

How is it in your database? If both have a foreign key to workflow, then both get a Workflow property mapped as:

References(Function(x) x.Workflow)

in each mapping class. If only the Page has it, and the Region's is therefore inferred, add an unmapped readonly property on Region thus:

public Workflow Workflow { get { return Page.Workflow; } }
David M
Hi. Both have a foreign key. But how do I map the inverse relationship? I thought you had to use a HasMany() on the other side of a relationship from References()?I'm also slightly confused as to where best to use Inverse and Cascade ...
Matt Thrower