Filter & Databinding

Posts   
 
    
Randy
User
Posts: 7
Joined: 25-Sep-2005
# Posted on: 25-Sep-2005 03:27:19   

Hey All,

This is my first time using LLBLGEN Pro and I am a little confused about predicate expressions.

I have 4 tables: State City (state_id FK) Property Type Listing (city_id FK, property_type FK)

I am trying to figure out the best way to bring back a collection (based on filter criteria) that I can bind to a GridView control.

For example, I want to bring back all listings with a property type of 2, in state 1, etc.

Here is what I used on another page and it worked, but it only had one predicate and was binding to a DropDownList:

IPredicateExpression myFilter = new PredicateExpression();

myFilter.Add(PredicateFactory.CompareValue(GeneratedNamespace.CityFieldIndex.StateId, ComparisonOperator.Equal, state.SelectedValue));

myCities.GetMulti(myFilter);

I hope this makes sense and thanks for the help! So far I am extremely excited about LLBLGEN!!

Randy

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 25-Sep-2005 17:23:20   

Chapter titled 'filtering and sorting' in the user guide discusses this type of query. Have look at section ‘Multi-entity filters’ . let me know if this does not help.

Randy
User
Posts: 7
Joined: 25-Sep-2005
# Posted on: 25-Sep-2005 18:25:58   

I had ran across that and tried it, but without success. The example was for adapter and I'm using self-servicing. Here is what I had:

ListingCollection myListings = new ListingCollection();

RelationPredicateBucket bucket = new RelationPredicateBucket(); bucket.Relations.Add(ListingEntity.Relations.CityEntityUsingCityId); bucket.Relations.Add(CityEntity.Relations.StateEntityUsingStateId);
bucket.PredicateExpression.Add(PredicateFactory.CompareValue(PremierFSBODAL.StateFieldIndex.StateId, ComparisonOperator.Equal, state)); myListings.GetMulti(bucket.PredicateExpression);

Thanks, Randy

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 25-Sep-2005 19:33:43   

There is a Self Service example. Look at User guide

Using Generater Code -->Self Service -->Filtering and Sorting

I have pasted the example which is as below:

// [C#]
CustomerCollection customers = new CustomerCollection();
RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(CustomerEntity.Relations.OrderEntityUsingCustomerID);
relationsToUse.Add(OrderEntity.Relations.OrderDetailsEntityUsingOrderID);
relationsToUse.Add(OrderDetailsEntity.Relations.ProductEntityUsingProductID);
relationsToUse.Add(ProductEntity.Relations.SupplierEntityUsingSupplierID);
IPredicateExpression selectFilter = new PredicateExpression();
selectFilter.Add(PredicateFactory.CompareValue(SupplierFieldIndex.Country, ComparisonOperator.Equal, "France"));
customers.GetMulti(selectFilter, 0, null, relationsToUse);

therefore, perhaps your solution copuld be something like:


ListingCollection myListings = new ListingCollection();
RelationCollection relationsToUse = new RelationCollection();

relationsToUse.Add(ListingEntity.Relations.CityEntityUsingCityId);
relationsToUse.Add(CityEntity.Relations.StateEntityUsingStateId);

IPredicateExpression selectFilter = new PredicateExpression();

selectFilter.Add(PredicateFactory.CompareValue(PremierFSBODAL.StateFieldIndex.StateId, ComparisonOperator.Equal, stateValue));
selectFilter.Add(PredicateFactory.CompareValue(PremierFSBODAL.PropertyFieldIndex.Property_idId, ComparisonOperator.Equal, ProperTypeValue));

myListings.GetMulti(selectFilter, 0, null, relationsToUse);

Please let me know how this goes with you.

Randy
User
Posts: 7
Joined: 25-Sep-2005
# Posted on: 25-Sep-2005 20:09:06   

Sorry, it was getting late and I must have missed that example.

Thanks for your help, it worked perfectly!

Randy

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 25-Sep-2005 20:28:55   

Good to hear that. Thanks for the feedback. simple_smile