Is there any way to get Nhibernate mapping to perform a join between a child and par开发者_Go百科ent 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?
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.
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 :)
精彩评论