开发者

How to define recursive Property in Castle ActiveRecord?

开发者 https://www.devze.com 2023-01-05 09:17 出处:网络
Suppose you have a class named MyClas开发者_如何学Cs. MyClass should have a property named Parent, Parent must be of type MyClass itself. It is necessary because MyClass wants to hold a tree structure

Suppose you have a class named MyClas开发者_如何学Cs. MyClass should have a property named Parent, Parent must be of type MyClass itself. It is necessary because MyClass wants to hold a tree structure.

How can it be done?


It's pretty straightforward:

[ActiveRecord(Lazy = true)]
public class MyClass {
  [BelongsTo]
  public virtual MyClass Parent { get;set; }
}

You might also want to map the collection of children.

See these articles for more information on how to run recursive queries over this:

  • http://ayende.com/Blog/archive/2006/11/22/ComplexQueriesWithActiveRecord.aspx
  • http://web.archive.org/web/20090806071731/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/05/14/how-to-map-a-tree-in-nhibernate.aspx
  • http://ayende.com/Blog/archive/2009/08/28/nhibernate-tips-amp-tricks-efficiently-selecting-a-tree.aspx
0

精彩评论

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