stored procedures and predicate expressions

Posts   
 
    
kincho
User
Posts: 2
Joined: 04-Apr-2007
# Posted on: 04-Apr-2007 13:34:17   

hi,

i have this stored procedure:

CREATE PROCEDURE dbo.usp_NearbyEntities
    @Longitude float, 
    @Latitude float, 
    @Distance float
AS  
BEGIN 
    SELECT E.IdEntita as IdEntita
    FROM dbo.Lokalizacia L INNER JOIN
        dbo.Entita E ON L.IdLokalizacia = E.IdLokalizacia
    WHERE Acos( Sin( Pi()/180*@Latitude ) * Sin( Pi()/180*L.Latitude ) + Cos( Pi()/180*@Latitude ) * Cos( Pi()/180*L.Latitude ) * Cos( Pi()/180*L.Longitude - Pi()/180*@Longitude ) ) * 6378.1 <= @Distance
END
GO

which when called as a retrieval stored procedure returns a DataTable consisting of a single column IdEntita containing those ids which match the "nearby entity" criterion

then i have a few other criteria, but for that i use PredicateExpression to assemble the filter

now i would like to combine these two filters. at the present i do it very clumsily:

foreach (DataRow myRow in tableToFill.Rows)
{
    decimal id = (decimal)myRow["IdEntita"];
    predicate.AddWithOr( PredicateFactory.CompareValue( EntitaFieldIndex.IdEntita, ComparisonOperator.Equal, id ) );
}

this "predicate" is then added to the predicate expression with the other criteria.

i wonder if there is a way to do the same in one go instead of going through the loop

i'm using LLBLGen Pro v. 1.0.2005.1 Visual Studio 2003 self-servicing SQL Server 2000

thanks for any suggestions, kincho

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 04-Apr-2007 16:20:00   

Do you want to filter rows in the database, or you want to filter rows after being fetched from the database?

kincho
User
Posts: 2
Joined: 04-Apr-2007
# Posted on: 05-Apr-2007 16:51:09   

well, ultimately i want to filter rows in the database. by using the LLBL predicate expression construct and one stored procedure.

the pseudocode should look something like this:

MyCollection result = new MyCollection();

RelationCollection relations = new RelationCollection();
relations.Add( all the needed relations between tables );

PredicateExpression filter = new PredicateExpression();
filter.Add( all the crazy filters like 'date range', 'number of views', ... );
filter.Add( the nearby entity filter );

result.GetMulti(filter, relations);

return result;

i don't know if this is even possible.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 05-Apr-2007 17:02:59   

I don't think that's possible. A database stored procedure only accepts parameters, and that's it. It does the filtering itself.