开发者

How do I map to a parent or child in the same table with NHibernate?

Lets suppose that I have a Category table with a column that holds the id of a par开发者_如何转开发ent or child category from the same table. This design would allow me to have unlimited levels of Categories, or unlimited levels in a thread, for example.

How can I map this relationship with NHibernate? Are there any disadvantages or warnings that I should take into consideration when doing this?


You map it as ny other many-to-one:

<class name="foo" class="mylib.fooclass">
    <id>...</id>
    ...

    <many-to-one name="ParentFoo" type="mylib.fooclass" column="parentId" />
</class>

the only warning is to take care with circular references as well as non-lazyloaded collections and properties...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜