Where not in ... ?

Posts   
 
    
glennpd
User
Posts: 30
Joined: 09-Feb-2006
# Posted on: 06-Mar-2006 21:29:32   

How would I configure a new style filte condition to present the equivalent of:

Select ISBN, Title, Price from MyTitles where Author like "Thompson%" and isbn not in (select ISBN from YourTitles where Author like "Thompson%")

Thanks

Glenn

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 07-Mar-2006 02:56:17   

From the manual.

How do I write a filter which does WHERE field IN (SELECT fieldb FROM foo) ?
    SelfServicing
// C#
IPredicateExpression filter = new PredicateExpression();
filter.Add(new FieldCompareSetPredicate(
    YourEntityFields.Field, FooFields.Fieldb, SetOperator.In, null);
' VB.NET
Dim filter As New PredicateExpression()
filter.Add(new FieldCompareSetPredicate( _
    YourEntityFields.Field, FooFields.Fieldb, _
    SetOperator.In, Nothing))

    Adapter
// C#
IPredicateExpression filter = new PredicateExpression();
filter.Add(new FieldCompareSetPredicate(
    YourEntityFields.Field, null, FooFields.Fieldb, null, 
    SetOperator.In, null));
' VB.NET
Dim filter As New PredicateExpression()
filter.Add(new FieldCompareSetPredicate( _
    YourEntityFields.Field, Nothing, FooFields.Fieldb, Nothing, _
    SetOperator.In, Nothing))

The FieldCompareSetPredicate has a negate bool that you can use to make this predicate a not in

glennpd
User
Posts: 30
Joined: 09-Feb-2006
# Posted on: 09-Mar-2006 17:21:34   

Thanks for the example, but what I was looking for was how to express this using the "New" format.

Thanks

Glenn

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 09-Mar-2006 19:16:40   

!(CustomerFields.CompanyName % "Solutions%");

Frans Bouma | Lead developer LLBLGen Pro
glennpd
User
Posts: 30
Joined: 09-Feb-2006
# Posted on: 09-Mar-2006 19:26:25   

I appologize, but I am a newbie. How would I express this

Select ISBN, Title, Price from MyTitles where Author like "Thompson%" and isbn not in (select ISBN from YourTitles where Author like "Thompson%")

using the new syntax for a filter expression.

Thanks

Glenn

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Mar-2006 16:09:56   

Assuming you are using the Adapter scenario, the following code may do the trick.


IPredicateExpression filter = new PredicateExpression();            

filter.Add(PredicateFactory.Like(MyTitlesFieldIndex.Author, "Thompson%"));

filter.Add(new FieldCompareSetPredicate(EntityFieldFactory.Create(MyTitlesFieldIndex.Isbn), null, EntityFieldFactory.Create(YourTitlesFieldIndex.Isbn), null, SetOperator.In, PredicateFactory.Like(YourTitlesFieldIndex.Author, "Thompson%"), true) );


RelationPredicateBucket Bucket = new RelationPredicateBucket();
Bucket.PredicateExpression.Add(filter);
            
DataAccessAdapter adapter = new DataAccessAdapter();
myTitles  = new EntityCollection(new MyTitlesEntityFactory());
adapter.FetchEntityCollection(myTitles, Bucket);

You can use the same filter to fetch a TypedList, TypedView or a dynamicList, I just assumed you were fetching into an EntityCollection

glennpd
User
Posts: 30
Joined: 09-Feb-2006
# Posted on: 11-Mar-2006 00:01:03   

Excellent example using the "Old" syntax, but what I am interested in is the "New" syntax. As Otis suggersted. Unfortunatly Otis did not create the entire filter.

Thanks

Glenn

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 11-Mar-2006 10:02:20   

glennpd wrote:

Excellent example using the "Old" syntax, but what I am interested in is the "New" syntax. As Otis suggersted. Unfortunatly Otis did not create the entire filter.

Well, the equivalents of one another are in the manual, but you've to understand that not every predicate has an operator equivalent. So fieldcompareset is still build with a fieldcomparesetpredicate class. ->


RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(MyTitlesFields.Author % "Thompson%");
bucket.PredicateExpression.AddWithAnd(new FieldCompareSetPredicate(MyTitlesFields.Isbn, null, YourTitlesFields.Isbn, null, SetOperator.In, (YourTitlesFields.Author % "Thompson%"), true) );
DataAccessAdapter adapter = new DataAccessAdapter();
myTitles = new EntityCollection(new MyTitlesEntityFactory());
adapter.FetchEntityCollection(myTitles, Bucket);

Frans Bouma | Lead developer LLBLGen Pro
glennpd
User
Posts: 30
Joined: 09-Feb-2006
# Posted on: 11-Mar-2006 12:23:59   

Thanks Otis, that cleared it up. I could not see how this could be accomplished without the ungainly unintuitive predicate syntax.

Thanks

Glenn