开发者

Ordered many-to-many relationship in NHibernate

Let's say I have two classes: Item and ItemCollection, where ItemCollection contains an ordered list of Item objects with an index, i.e. the list is ordered in a way specified by the user.

Let's also say that they have a many-to-many relationship, an ItemCollection can contain many items and an Item can belong to several ItemCollections.

That would, in my head, require three tables in the database. One for Item, one for ItemCollection and one for the ordered mapping. The mapping table would contain thre开发者_运维问答e columns:

int ItemID
int ItemCollectionID
int ListIndex

QUESTION: How would you design the ItemCollection class? Should the list of Item objects be a list, dictionary or other? What would the NHibernate mapping look like to get the ListIndex into the picture?


If you're using Fluent NHibernate, you'll find an answer in the HasMany mapping in the code for OrderMapping in this article.

For traditional hibernate mapping (XML file), see chapter 21.3 of the NHibernate documentation here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜