title: How to Call Database Stored Function via Fluent Nhibernate and Get IQueryable<T> as a Result
body: <p>I have stored database function for calculated nearest locations:</p>
  
  <pre><code>CREATE FUNCTION LoadNearBusinesses
      (
          @latitude DECIMAL(25, 10),
          @longtitude DECIMAL(25, 10),
          @areaRadius DECIMAL(25, 10)
      )
      RETURNS TABLE
      AS
      return SELECT DISTINCT [Business].* FROM [Business] 
       LEFT JOIN [BusinessLocation] ON [BusinessLocation].Business_id = [Business].Id 
       LEFT JOIN [Location] ON [BusinessLocation].Id = [Location].Id
       WHERE 6371 * ACos(COS(@latitude* PI() / 180) * Cos([Location].Latitude * PI() / 180) * Cos(([Location].Longitude- @longtitude)* PI() / 180) + SIN(@latitude* PI() / 180) * Sin([Location].Latitude* PI() / 180)) &lt;= @areaRadius;
  </code></pre>
  
  <p>And now I need to call this function from my code and get <strong>IQueryable&lt;<em>Business</strong>></em> as a result for using it in telerik grids.</p>
  
  <p>I try:</p>
  
  <pre><code>Session.CreateSQLQuery(
                  string.Format(@"SELECT * FROM [dbo].[LoadNearBusinesses]({0},{1},{2})",
                  latitude, longitude, radius)).AddEntity(typeof(Business)).List&lt;Business&gt;();
  </code></pre>
  
  <p>But this is List, and when when I add additional filtration it will be executed in memory, not in database.</p>
  
  <p>Have you any ideas? Thanks.</p>