How do I add a '1 = 1' where clause?

Posts   
 
   
 
Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 16-Apr-2008 14:28:20   

Hi guys,

Am trying to generate some sql that does the following:


Select * from Product 

Where (1 = 1)

And ( dynamic clause 1)

And ( dynamic clause 2)

There maybe 0 dynamic clauses, there maybe many dynamic clauses and the ones included will be different for each query.

How can I create a PredicateExpression that will output as '1 = 1'? Or is there some over way to handle this?

Cheers,

Pete

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 16-Apr-2008 15:50:13   

Well in case of 0 dynamic clauses, all you have to do is to use no predicate expression with the fetch method.

Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 17-Apr-2008 00:23:30   

Yes but if I can't use a '1 = 1' style predicate, I have to track whether I have added a predicate so I know whether to use .Add() or .AddWithAnd()

Am currently using a ProductId > 0 predicate as it always true but I don't know, it feels hacky

Pete

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Apr-2008 07:29:41   

the .AddWithAnd method works in both cases (empty predicateExpression and non-empty predicateExpression) so you could use it no mather the number of existing clausses. Conclusion: you don't have to include an "1 = 1" clause simple_smile

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-Apr-2008 09:37:52   

in fact, 'Add()' does an AddWithAnd wink

Frans Bouma | Lead developer LLBLGen Pro
Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 17-Apr-2008 19:53:55   

And that would be jsut what i wanted to hear. Cheers guys simple_smile

Pete