views:

30

answers:

1

Hi,

Suppose you have a class named MyClass. MyClass should have a property named Parent, Parent must be of type MyClass itslef. It is necessary because MyClass wants to hold a tree structure.

How can it be done?

A: 

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:

Mauricio Scheffer
@Mauricio: tnks, your solution worked good. Also this way work too: `[BelongsTo("MyClass")] public virtual MayClass Parent { set; get; ` In this way a column with name `MyClass` is created instead of a column named `Parent`
afsharm