Thanks Carl, that makes a lot of sense. So just to confirm, if I use an IList to store the versions and specify OrderBy() in my mapping, then they will come out in the required order, even if the mapping specifies AsBag()?
--- Tim On Wednesday, December 19, 2012 2:07:29 PM UTC, Carl B wrote: > > A List is a specifically, sequentially-ordered set of items, which has an > index column in the database that says what the order is. This is useful > when you have items that have an arbitrary (e.g., user-defined) order. > > In your scenario, it sounds like you have a Bag (or more likely, a Set, > because the same "version" could not appear in the same "document" more > than once, but sets aren't particularly easy to order). NHibernate can map > a Bag onto IList or ICollection, and since you want to have the items in a > specific order, it sounds like you need the IList. > > .AsList() tells NH to treat the association as a LIST, .AsSet() tells it > to treat it as a SET, and .AsBag() [which is the default] says to treat it > as a Bag. > > See also > http://stackoverflow.com/questions/1916350/list-vs-set-vs-bag-in-nhibernate > > On Wed, Dec 19, 2012 at 8:20 AM, Tim Robinson > <tim.j.r...@gmail.com<javascript:> > > wrote: > >> Hi, >> >> In my data model I have a simple situation with document which has many >> versions. I want the versions to be retrieved in order (most recent first) >> so I have mapped the association like this >> >> HasMany(x => x.Versions) >> .AsList() >> .OrderBy("UpdateDate DESC") >> .KeyColumn("DocumentId") >> .Inverse() >> .Cascade.AllDeleteOrphan(); >> >> The problem is that when nhibernate generates the SQL, it tries to >> retrieve a nonexistent column called 'index' from the database. If I take >> out the AsList() specifier it seems to work OK and returns them in the >> correct order but I'm not sure whether this is just luck. can anyone >> explain what AsList is actually supposed to do? >> >> I've read about indexed and ordered collections in the jboss hibernate >> documentation but it's not really clear how it all translates into fnh >> >> --- Tim >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Fluent NHibernate" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/fluent-nhibernate/-/fpPtoQCMjBsJ. >> To post to this group, send email to >> fluent-n...@googlegroups.com<javascript:> >> . >> To unsubscribe from this group, send email to >> fluent-nhibern...@googlegroups.com <javascript:>. >> For more options, visit this group at >> http://groups.google.com/group/fluent-nhibernate?hl=en. >> > > -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To view this discussion on the web visit https://groups.google.com/d/msg/fluent-nhibernate/-/tK4RiK2V5tMJ. To post to this group, send email to fluent-nhibernate@googlegroups.com. To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.