Can Query-by-Example be done in CSLA

Can Query-by-Example be done in CSLA

Old forum URL: forums.lhotka.net/forums/t/209.aspx


Steven posted on Friday, May 26, 2006

 

I am trying to duplicate a Query-by-Example capability in an existing application that I am porting to CSLA.

 

The current application has a toolbar button that when pressed puts an operator button next to each textbox and combobox on the form.  The user can click the operator button to toggle between the following operator choices.

 

None, Equal, Not Equal, Less Than, Less Than or Equal, Greater than, Greater Than or Equal, Like, Not Like.

 

The buttons all start out set as None and then toggle through the other choices each time it is clicked.

 

The user is free to enter selection criteria in any combination of fields on the form and have any field’s operator set to any of the states listed above.  So For example the following criteria to find All employees that started  before 1/1/2000 that live in CA and are 65 or over:

“Start Date: 1/1/2000” with operator of  <

“State: CA” with operator of =

“Age: 65” with operator of >=

 

So my question is with regards to CSLA would this be implemented by creating a Criteria class that includes all of the fields in the BO or is there a better way?  Also, I didn’t see any example of the Criteria class providing an operator for each of its fields. For example if criteria contained Age am I only able to filter for just one age or can I say I want return all records with an age above a specified age.

 

If anyone here has implemented similar functionality can you gives some information on how you have implemented this.  I didn’t see this covered in the book, did I miss it?

 

Thanks

ajj3085 replied on Friday, May 26, 2006

This isn't covered in the book (although I haven't finishd the 2nd edition yet).

Your best bet may be to create an object, PersonSearcher, which is a business object, that implements the behavior you want.

I did some search functionality, but it was a bit simpler; everything the user entered was a substring search.  So I had a SearchCriteria class, which instead of being private was public.  I then bound the search form inputs to the various properties.

I then exposed a static Fetch method which accepted this criteria class and the method basically passed this to the DataPortal Fetch. 

The only part I don't like is the exposing of the Criteria class... but I didn't want to make another class which was basically identical.

Andy

Q Johnson replied on Friday, June 09, 2006

There was an excellent thread in which a general purpose search/filter form was contributed by the participants (largely the work of JCasa as I recall - haven't seen his postings on the board in a while) that may interest you.  You can find it in the old forum at this URL:
 
    http://groups.msn.com/CSLANET/general.msnw?action=get_message&mview=0&ID_Message=15114
 
There are 68 postings on the thread, so you'll need some time to digest it all.  But you'll likely find it useful.
 
One cautionary item:  be careful if you try to create that "Criteria" class you mentioned in a generic fashion in your posting.  There is a Criteria Class in CSLA that will likely cause some ambiguity issues for you (and anyone you happen to discuss it with, too!! <g>).


From: Steven [mailto:cslanet@lhotka.net]
Sent: Friday, May 26, 2006 1:48 PM
To: QJohnson@TeamNFP.com
Subject: [CSLA .NET] Can Query-by-Example be done in CSLA

I am trying to duplicate a Query-by-Example capability in an existing application that I am porting to CSLA.

The current application has a toolbar button that when pressed puts an operator button next to each textbox and combobox on the form.  The user can click the operator button to toggle between the following operator choices.

None, Equal, Not Equal, Less Than, Less Than or Equal, Greater than, Greater Than or Equal, Like, Not Like.

The buttons all start out set as None and then toggle through the other choices each time it is clicked.

The user is free to enter selection criteria in any combination of fields on the form and have any fieldbs operator set to any of the states listed above.  So For example the following criteria to find All employees that started  before 1/1/2000 that live in CA and are 65 or over:

bStart Date: 1/1/2000b with operator of  <

bState: CAb with operator of =

bAge: 65b with operator of >=

So my question is with regards to CSLA would this be implemented by creating a Criteria class that includes all of the fields in the BO or is there a better way?  Also, I didnbt see any example of the Criteria class providing an operator for each of its fields. For example if criteria contained Age am I only able to filter for just one age or can I say I want return all records with an age above a specified age.

If anyone here has implemented similar functionality can you gives some information on how you have implemented this.  I didnbt see this covered in the book, did I miss it?

Thanks




Copyright (c) Marimer LLC