Add plain SQL to a LLBLGen Pro - Collection

Posts   
 
    
SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 11-Jan-2007 07:57:20   

Hi,

I know its not the way of doing this normally, but sometimes i want to add some query-text to a query which is a LLBLGen Pro - Collection.

I've for example the following for the WHERE clause:

AND DocID IN (
    SELECT DocID
    FROM Documenten
    WHERE (DocContactID = 2 OR DocContactID IN (SELECT CGContactID FROM ContactGebr WHERE CGGebrID=12)
    UNION
    SELECT DocID
        FROM Documenten, DocDoc, DocRoutes, DocRouteGebruikers
    WHERE DDDocID2 = DocID
    AND DDDocID1 = RouteDocID
    AND RGRouteID = RouteID
    AND RGGebrID = 12))

I know it's all possible to put this in a PredicateExpression but is there a way to add this standard SQL to a LLBLGenPro - Collection?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jan-2007 15:02:38   

I know it's all possible to put this in a PredicateExpression but is there a way to add this standard SQL to a LLBLGenPro - Collection?

Regardeless of the query itself (coz I can't understand it without knowing the relevant tables structures and which is the collection you are fetching)

If you are using SelfServicing, you may extend the EntityCollection class (using the partial keyword), add a new method that wraps the base.GetMulti() method. So you can add the predicate expression that you want, and pass it to the GetMulti().

In adapter this can be better done in a BL method that calls the DAL ( adpater.FetchEntityCollection() )

SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 12-Jan-2007 12:10:38   

Is it possible to add this SQL-WHERE clause (of course without the keyword WHERE) in a predicate expression without writing it the normal (Object Orientied) way. So without writing a RelationCollection etc, just plump the text in de predicate expression? I need it only one time, so I know I wan't it in a quick and dirty way....

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jan-2007 15:32:02   

I need it only one time, so I know I wan't it in a quick and dirty way....

If you are gonna write it once, why do you want to write it in a dirty way? simple_smile

Otherwise you may want to use a storedProcedure, and then you can project the returned resultSet to a an EntityCollection.

SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 13-Jan-2007 22:12:40   

So is my conclusion right that there is no other way to add "navtive SQL" to an entitycollection / predicate-expression?

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 14-Jan-2007 00:12:41   

You could create a class that inherits from SD.LLBLGen.Pro.ORMSupportClasses.IPredicate and embed your custom SQL in the ToQueryText method.

SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 15-Jan-2007 10:29:17   

Thanks,

I created the following class and all works fine:

    public class FreePredicate : SD.LLBLGen.Pro.ORMSupportClasses.Predicate
    {
        string _filter;

        public FreePredicate(string filter)
        {
            _filter = filter;
        }

        public override string ToQueryText(ref int uniqueMarker)
        {
            return _filter;
        }

        public override string ToQueryText(ref int uniqueMarker, bool inHavingClause)
        {
            return _filter;
        }
    }