You are using the wrong model. I have solved a similar problem by using

[ActiveRecord]
public class Document
{
  [HasMany]
  public IList<DocumentVersion> Versions {get;set;}

  [BelongsTo]
  public DocumentVersion LatestVersion {get;set;}

  public DocumentVersion CreateNewVersion()
  {
    // logic for creating new DocumentVersion
    // also updates LatestVersion and Versions list
  }
}

[ActiveRecord]
public class DocumentVersion
{
  [BelongsTo]
  public Document Document {get;set;}
}

If you really have to use one class only, try this:

[ActiveRecord]
public class Document
{
  [BelongsTo]
  public Document Parent {get;set;}

  [BelongsTo]
  public Document OriginalVersion {get;set;}

  [BelongsTo]
  public Document LatestVersion {get;set;}

  public Document CreateNewVersion()
  {
    // logic for creating new Document version
    // also updates LatestVersion on all ancestors
  }
}

-Markus

2010/3/18 chitech <[email protected]>:
> Alo
>
> I have a document object which can have one parent document and one
> child document. A chain like this:
>
> first version document (no parent, one child) - second version
> document (one parent, one child) - third version document (one parent,
> no child)
>
> I have this mapping:
>
>    [ActiveRecord(Lazy = true)]
>    public class Registration
>    {
>        [BelongsTo("ParentDocumentId")]
>        public virtual Document ParentDocument { get; set; }
>
>        [HasMany]
>        public virtual IList<Document> ChildDocuments { get; set; }
>
>        public virtual Document ChildDocument
>        {
>            get
>            {
>                return ChildDocuments != null && ChildDocuments.Count
> == 1 ? ChildDocuments[0] : null;
>            }
>            set
>            {
>                if (ChildDocuments == null) ChildDocuments = new
> List<Document>();
>                ChildDocuments.Add(value);
>            }
>        }
>    }
>
> How can I make a query to get the last Document (third version
> document). I can't really figure out how to use HQL or criteria to
> solve this problem.
>
> Thx in advance
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Castle Project Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/castle-project-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to