Markus is right, list are implicitly ordered - take a look at the following posts:
http://ayende.com/Blog/archive/2009/06/02/nhibernate-mapping-ltlistgt.aspx <http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/06/12/mapping-collections-in-nhibernate-part-1.aspx> http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/06/12/mapping-collections-in-nhibernate-part-1.aspx <http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/06/12/mapping-collections-in-nhibernate-part-1.aspx>For more details around the different collection types in NHibernate. In my example VersionNumber is a synthetic version identifier (i.e. a version identifier that might be meaningful to the business) - I used an incrementing integer, but it could be anything - this wouldn't necessarily be position related i.e. imagine for example once you got to 20 versions, older versions were removed from the database / archived / whatever - the synthetic identifier would still remain the same, where as the list element position numbers may shift around as elements are removed from the version list. The Synthetic version number is also handy when you start using things like nhibernate search ( http://ayende.com/Blog/archive/2009/05/03/nhibernate-search-again.aspx). Cheers, - Alex On Tue, Mar 23, 2010 at 2:40 AM, 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%[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%[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]<castle-project-users%[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.
