So we add a new column on DocumentVersion (VersionNumber) to keep track of the version chain. Is make sense. Thx
On Mar 22, 10:44 am, Alex Henderson <[email protected]> wrote: > All versions (including the latest) would belong to the versions collection: > > [HasMany] > public IList<DocumentVersion> Versions {get;set;} > > so, you might have something like this as a method on your Document class: > > public virtual DocumentVersion NewVersion() > { > DocumentVersion newVersion = new DocumentVersion > { > Document = this; > VersionNumber = LatestVersion.VersionNumber + 1; > } > > LatestVersion = newVersion; > > Versions.Add(newVersion); > > return newVersion; > > } > > Then when updating the document you do something along the lines of: > > var newVersion = document.NewVersion(); > newVersion.XXXX = value; > > document.Save(); // or Repository<Document>.Update(document) etc. > > Make sense? > > Cheers, > > - Alex > > > > On Mon, Mar 22, 2010 at 10:10 PM, chitech <[email protected]> wrote: > > 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.
