why doesn't this work...

Posts   
 
    
Posts: 2
Joined: 23-Feb-2010
# Posted on: 23-Feb-2010 08:57:49   

Hi -

I'm not sure why this code doesn't work, I'm pretty sure it should do... note if I use the ADDWITHOR operator it returns correctly all the OR'd fields... if I use the ADDWITHAND I don't get any results back, even thou it definitely occurs correctly. Can anyone help, I'm stuck about how to achieve this.

cake.CollectionClasses.ItemCollection _cMasterItem = new cake.CollectionClasses.ItemCollection();

                RelationCollection relationsToUse = new RelationCollection();
                relationsToUse.Add(cake.EntityClasses.ItemEntity.Relations.TagOccuranceEntityUsingItemId);
                relationsToUse.Add(cake.EntityClasses.TagOccuranceEntity.Relations.TagListEntityUsingTagId);

                PredicateExpression _fItems = new PredicateExpression();
                int _AddCount = 0; 


                foreach (string _tag in _searchByTags)
                {
                    _AddCount++;
                    if (_AddCount == 1)
                    {
                        _fItems.Add(cake.HelperClasses.TagListFields.Tag == _tag.Trim()); 

                    }
                    else
                    {
                        _fItems.AddWithAnd(cake.HelperClasses.TagListFields.Tag == _tag.Trim());
                    }
                }

                 _cMasterItem.GetMulti(_fItems, 0, null, relationsToUse);

Maybe there's a better way of doing this, but I couldn't figure it out. I tried using compare fieldrange predicate, but this uses an OR and there doesn't seem to be any why to make it use ANDs.

I throw myself at your mercy wink

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 23-Feb-2010 09:11:04   

I see nothing wrong in your code, so you'd better examine the generated query and run it against the database to see the results.

Most probably one of the tags doesn't match what's in the database, espaecially after it's trimmed. You can test this y trying to use Like 'xxx%'

Anyway runing the query will reviel what's happening.

Posts: 2
Joined: 23-Feb-2010
# Posted on: 23-Feb-2010 10:33:36   

Walaa wrote:

I see nothing wrong in your code, so you'd better examine the generated query and run it against the database to see the results.

Most probably one of the tags doesn't match what's in the database, espaecially after it's trimmed. You can test this y trying to use Like 'xxx%'

Anyway runing the query will reviel what's happening.

What's weird is it works with OR.

I'll see if I can find the query it generates so I can post it here..

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 23-Feb-2010 11:05:39   

Oops, I spoke too soone when I said your code should work.

Definitly it can' work (SQL wise).

As you are joining to the table you are filtering upon, and the same field can't have different values at the same time (since you are using AND), that's why OR did work.

First thing you need to do, is to ocme up with the correct SQL query, then you can think of how to write it with LLBLGen.