OrderBy property in the mapping file

531 views
Skip to first unread message

seekay

unread,
May 4, 2011, 10:46:46 AM5/4/11
to Fluent NHibernate
Hi,
New to FNH and NHibernate as well. I'm trying to order a child
collection using the OrderBy property in the mapping file.

public class SectionMap : EntityBaseMap<Section>
{
public SectionMap()
{
Map(x => x.Name);
Map(x => x.Sortorder);
Map(x => x.RedirectUrl);
HasMany(x => x.Pages)
.AsBag()
.OrderBy("Sortorder ASC")
.Inverse()
.Cascade.All();
}
}

Here's how I get the a list of the Parent objects:

IList<Section> sectionPageList = session.QueryOver<Section>()
.OrderBy(x =>
x.Sortorder).Asc()
.List();

For some reason, the 'Order By' specified in the mapping file above
doesn't seem to be working. The parent sections are ordered correctly
because of the explicit OrderBy clause, but the lazy-loaded children
aren't. I exported the .hbm.xml files and there's no order-by
attribute generated. Using FluentNHibernate v1.2.0.712 obtained via
NuGet.

It feels as though I'm missing something small and stupid, but unable
to put my finger on it. Thanks!

James Gregory

unread,
May 12, 2011, 4:14:46 PM5/12/11
to fluent-n...@googlegroups.com
I've just tried to reproduce this, and can't. I used the same version of FNH, and it's correctly writing out the order-by attribute (and affecting the queries). Could you create a test case to show this? Or a sln with a simple example.

gleb Chermennov

unread,
Sep 11, 2012, 1:29:35 PM9/11/12
to fluent-n...@googlegroups.com, seek...@gmail.com
I understand that may sound odd, but what exactly do you do in EntityBaseMap<T> class? May be some code that gets executed in the base class messes up derived classes somehow?

среда, 4 мая 2011 г., 18:46:46 UTC+4 пользователь seekay написал:
Reply all
Reply to author
Forward
0 new messages