Many thanks for the responses. In this case, using the "formula"
attribute gave me the behaviour I wanted.

Owen

On Apr 2, 7:20 pm, Diego Mijelshon <[email protected]> wrote:
> Create a property mapping on that case expression and use it for sorting.
> Example: <property name="WeirdSortingProperty" formula="case orderCol ..."
> />
>
>    Diego
>
> On Fri, Apr 2, 2010 at 12:47, OwenD <[email protected]> wrote:
> > Apologies for any errors in this question - I'm somewhat new to
> > NHibernate, LINQ and C#.
>
> > The essential situation is that I have a table "blah" that is mapped
> > to a Blah domain object by NHibernate (I've just made up the table
> > name etc. here). I want to perform a paginated search on the "blah"
> > table, and provide a custom ordering on one of its fields - i.e. the
> > SQL that I eventually want to be executed is something like:
>
> > select top 10 * from blah
> > where <search_criteria>
> > order by
> > case orderCol
> >        when 0 then 1
> >        when 1 then 0
> >        when 2 then 3
> >        when 3 then 2
> > else 4
> > end
>
> > (in this example the ordering is something completely artificial).
>
> > The C# code I'm executing is something like:
>
> > ISession.Linq<Blah>().Where(<search_criteria>).OrderBy(x =>
> > x.OrderCol, new CustomComparer())
>
> > where the CustomComparer() class implements my custom ordering
> > behaviour. However, when I monitor the SQL that NHibernate generates,
> > I just see something like:
>
> > select top 10 * from blah
> > where <search_criteria>
> > order by orderCol asc
>
> > (i.e my Comparer appears to be ignored - perhaps not too surprising).
> > My question is whether a custom ordering like this is even possible
> > using NHibernate?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en.

Reply via email to