I have some code which orders by a complex SQL projection. I've tried
many variations, but it seems like aliases arent replaced...

<code>
        protected DetachedCriteria GetProximityCriteria(Type type,
string alias, ILatLong origin, Distance radius, int limit)
        {
            DetachedCriteria dc = DetachedCriteria.For(type, "sub")
                .SetProjection(Projections.Id());

            // This should be very efficient if the latitude and
longitude columns are indexed
            BoundingBox bounds = new BoundingBox(origin, radius);
            AddBoundsRestriction(dc, "Latitude", "Longitude", bounds);

            if (limit > 0)
            {
                dc.SetMaxResults(limit);
                string latColumn = "{sub.Latitude}";
                string lngColumn = "{sub.Longitude}";

                // we have to project on distance and sort desc
                IProjection distanceProjection = GetDistanceProjection
( latColumn, lngColumn, origin, radius.Units);

                dc.AddOrder(Order.Desc(distanceProjection));
            }
            return dc;
        }
</code>
Note that "type" implements ILatLong which has Latitude and Longitude
properties.

Generated SQL is:
SQL: SELECT this_.venueid as venueid29_0_, this_.createdBy as
createdBy29_0_, this_.siteid as siteid29_0_, this_.venuetypeid as
venuetyp4_29_0_, this_.timezoneid as timezoneid29_0_, this_.venueName
as venueName29_0_, this_.streetaddress1 as streetad7_29_0_,
this_.streetaddress2 as streetad8_29_0_, this_.cityName as
cityName29_0_, this_.PhoneContact as PhoneCo10_29_0_, this_.cityId as
cityId29_0_, this_.stateProvinceId as statePr12_29_0_,
this_.countryCode as country13_29_0_, this_.postalcode as
postalcode29_0_, this_.websiteurl as websiteurl29_0_, this_.latitude
as latitude29_0_, this_.longitude as longitude29_0_, this_.description
as descrip18_29_0_, this_.Privacy as Privacy29_0_, this_.viewCount as
viewCount29_0_, this_.inserttimestamp as insertt21_29_0_,
this_.updatetimestamp as updatet22_29_0_
FROM EventSpace.dbo.cm_events_venue this_
WHERE this_.venueid in
 (SELECT top 10 this_0_.venueid as y0_
FROM EventSpace.dbo.cm_events_venue this_0_
WHERE ((this_0_.latitude > @p0 and this_0_.latitude < @p1) and
(this_0_.longitude > @p2 and this_0_.longitude < @p3))
ORDER BY 6376.774319 * Acos(sin(-1.47332316127622) * sin(radians
({sub}.latitude)) + cos(-1.47332316127622) * cos(radians
({sub}.latitude)) * cos(radians
(EventSpace.dbo.cm_events_venue.longitude)-0.588837699507983)) desc)


any clues ?


--~--~---------~--~----~------------~-------~--~----~
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