Perhaps this would be useful:

http://fabiomaulo.blogspot.se/2010/07/nhibernate-linq-provider-extension.html

/Oskar


Den 17 april 2012 00:21 skrev Marcelo Grossi <[email protected]>:
> Hi,
>
> I've managed to make my spatial queries work. But it's the most cost
> inefficient way possible. All the calculations are being done by code
> and not by the database itself. Case (a) below works but I think it
> retrieves all rows from my table and then calculates and filters it.
> Case (b) that doesn't work would be the ideal for me.
>
> case (a) -- WORKS!
>            ICriteria criteria = Session.CreateCriteria(typeof(T));
>            return (from t in criteria.List<T>()
>                   where t.GetLocation().GetDistance(location) <=
> radius
>                   select t).ToList<T>();
> case (b) -- DOES NOT WORK!!
>            return (from t in Session.Query<T>()
>                    where t.GetLocation().GetDistance(location) <=
> radius
>                    select t).ToList<T>();
> Throws:
> NHibernateMappings.Testing.NHibernateMappingTest.FindByVicinity:
> System.NotSupportedException : Double
> GetDistance(NHibernateMappings.Model.Location)
>
> Now I think this goes back to my original question. How do I map the
> function so that I make my case (b) work? Is it even possible?
>
> Any help is greatly appreciated,
>
> Thanks in advance,
>
> Marcelo Grossi
>
> On Apr 13, 7:32 pm, TheCPUWizard <[email protected]> wrote:
>> Some databases now have built in support so that what you are looking for
>> can be done completely DB server side....
>>
>>
>>
>>
>>
>>
>>
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]] On Behalf
>>
>> Of Marcelo Grossi
>> Sent: Friday, April 13, 2012 2:56 PM
>> To: nhusers
>> Subject: [nhusers] Mapping a scalar function?
>>
>> Hi all,
>>
>> I need a, very common nowadays, distance from locations filter. I have a
>> resource that has an address that itself have lat and long properties. I
>> also have a base location that I want to compare against all the resources
>> locations and filter out those who are at most "radius" meters distant from
>> my base location.
>>
>> I would like to use the linq notation to be consistent throughout my
>> project. I found out that you can re-write the SqlDialect to support a new
>> function. My question is: is this the only way or is there some special
>> mapping that I can make in order to map a function in my object to a
>> database filter call. Like so:
>>
>> from r in Resource
>> where r.DistanceFromLocation(constant_input_location) <=
>> constant_input_radius select r...
>>
>> This way in my entity mapping class (I'm using the Map By Code approach in
>> NH 3.2) I would simply map my function as if it were a property. Like so:
>>
>> Property(...);
>> CustomFunction(x => x.DistanceFromLocation, m => m...);
>>
>> I'm really new to both NHibernate and Mapping By Code so please bear with my
>> ignorance. Am I dreaming here or is this actually possible?
>>
>> Sorry in advance if this is too far-fetched. The thing is that NH does
>> everything I need and more so why not this? :-)
>>
>> Thanks in advance is anyone has any idea on the subject.
>>
>> --
>>
>> --
>> 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 
>> athttp://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.
>

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