tags:

views:

52

answers:

2

Is there any way to get Nhibernate mapping to perform a join between a child and parent tables

I have a product table and a product group table. there is a key between these tables of GroupId. When i use a join in mapping for a Product it tries to Join on the ProductId to the GroupId instead of the GroupId to GroupId.

Is there no easy way to do this?

A: 

Your mappings are probably wrong.

If Product has a reference (FK) to Group, it should be mapped as:

<many-to-one name="Group" column="GroupId"/>

If that's not the case, please post your classes.

Diego Mijelshon
Do you mean that I put the many-to-one inside the join statement? I can map it using this statement outside the join but it does'nt create an inner join and creates separate selects.
Phil Whittaker
What is the relationship between Product and Group? <join> is meant to map one entity to more than one table. Please post your classes and tables.
Diego Mijelshon
A: 

Is the foreign key set up in your database? If not add it in the database and try including it in the reference in your Nhibernate Product mapping:

e.g.,

<many-to-one name="Group" column="GroupId" foreign-key="FK_Product_ProductGroup" /> 

Note: foreign-key value there is just a guess of what it would be called, grab it from the database properties :)

Scozzard