creating IPedicates from an entityCollection

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 15-Aug-2007 16:37:57   

asp.net 2.0 llblgenpro 2 adapterTemplate

hiya,

I have a "search" textBox where a user can enter search values. These values then become predicates in my code behind.

 filter.AddWithOr(JobFields.jobDescription== txtSearch.Text);

Good so far. However, I still don't know how to do it with lookups,

eg, what happens if the user wants to enter a job category of "delivery"?

This value obviously represents a lookup value:

tblJob jobId (PK) jobDescription jobCategoryId (FK)

tblJobCategory jobCategoryId (PK) jobCategoryName

Let's say for arguments sake that: 1) my app is set up to search on word fragments. 2) the user enters "del"

The query will now go to the tblJobCategory and find 2 job category Id's:

jobCategoryId = 1 jobCategoryName ="delivery"

jobCategoryId = 2 jobCategoryName ="delete"

How would I add them both to my filter??

Would I create an filter factory that:

1) takes the filter + searchText as args 2) populates an entityCollection based on the searchText arg 3) loops thru this entityCollection and populates the filter with valid predicates 4) returns the filter as a function return value

I hope the above makes sense.

Any help appreciated.

many thanks,

yogi

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Aug-2007 17:06:01   

filter.AddWithOr(JobFields.jobDescription== txtSearch.Text);

Same way you are adding the above filter, you should add filters on related entities as follows:

filter.AddWithOr(CategoryFields.Name % "%del%");

But this time you should also add(define) an entityRelation to the related entity being filtered upon and add this to RelationCollection of the fetch method.

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 16-Aug-2007 11:52:55   

hiya,

Ok, I think I'm a bit further down the line.

I have done as advised but I don't get any values back.

I have ensured that:

1) there are valid values in the database. 2) I have removed all other filters, so that the issue is isolated.

Same way you are adding the above filter, you should add filters on related entities as follows: Code: filter.AddWithOr(CategoryFields.Name % "%del%");

But this time you should also:

a) add(define) an entityRelation to the related entity being filtered upon b) and add this to RelationCollection of the fetch method.



//the text is "Building Services", and there are several jobs in the database with this category.
//I have also removed ALL other filters, to ensure that this filter is the only issue.

string input = txtSearch.Text;   
 filter.Add(JobCategoryFields.JobCategoryName % "input%");  //"Building Services"

RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(JobEntity.Relations.JobCategoryEntityUsingJobCategoryId);

bucket.PredicateExpression.Add(filter);

DataAccessAdapter adp = new DataAccessAdapter();
EntityCollection<JobEntity> jobs = new EntityCollection<JobEntity>();
adp.FetchEntityCollection(jobs, bucket);

int jobCOunt = jobs.Count;   //empty :-(

Please note, I also tried:

bucket.Relations.Add(JobCategoryEntity.Relations.JobEntityUsingJobCategoryId);

But that didn't work either.

hmm, any ideas?Should I clarify anything?

many thanks,

yogi

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 16-Aug-2007 14:37:17   

hiya,

ok. solved it, I wasn't formatting the input variable properly. Thanks for your help Walaa.

yogisunglasses