You are right It's because ActiveRecord default use a Bag when using HasMany attribute
If I use this attribute: [HasMany( RelationType = RelationType.List, Index = "position")] I get the solution I want. I think I will use both a Position and VersionNumber column in DocumentVersion to get a ordered list and business version identifier Thx for solution. On Mar 22, 2:40 pm, Markus Zywitza <[email protected]> wrote: > Versions is an IList. Lists have an implicit order. > > -Markus > > 2010/3/22 chitech <[email protected]> > > > > > Alo Markus > > > I have a question about the solution with 2 table. How do you keep > > track of the DocumentVersion chain when you only save the > > LatestVersion? > > > On Mar 20, 7:22 pm, Markus Zywitza <[email protected]> wrote: > > > 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]<castle-project-users%2Bun > > [email protected]> > > . > > > > For more options, visit this group athttp:// > > 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]<castle-project-users%2Bun > > [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.
