开发者

many-to-many with different number of keys

I us开发者_运维知识库e NHibernate with mapping in the HBMs

I have Table1 like this

ID int(PK)
Category int(PK)
authorID int(PK)

And another table2 like this

A_ID int(PK)
Category int(PK)
NAME varcher(100)
PK_ID int

And I want data like this : ALL Table1 with collection of elements of table2.

My question : How I can define relationship many-to-many not by PK.

Pay attention : condition for join table1.Category=table2.Category AND table1.ID=table2.PK_ID

May be I have to change many-to-many?

Thanks


You are describing a One to Many relationship not Many to Many. There can not be a table2 record with many table1 records.

Your key is a Composite Key composited of Category and PK_ID

Have a look here for some sample code:
http://blog.raffaeu.com/archive/2009/03/19/nhibernate-collection-with-composite-id.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜