Searching Object with 2 or more properties that reference the same type

Posts   
 
    
bjacobs
User
Posts: 73
Joined: 20-Aug-2008
# Posted on: 11-Apr-2009 01:48:37   

How do I create a search filter that searches the following example:

Say I am searching a CarTrade object which has a BuyingVehicle (Vehicle Object) and a SellingVehicle (Vehicle Object). The Vehicle Object has a VIN number.

I want to search for all CarTrades where the BuyingVehicle.VIN is "X" and the SellingVehicle.VIN is "Y".

Could someone give me an example with this scenario?

Thanks,

Billy Jacobs

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Apr-2009 04:42:55   

Hi Billy,

You should use alias in the predicates. This is an example of that:

// setup the filter
IRelationPredicateBucket bucket = new RelationPredicateBucket();

// add the relations, as the end object is the same for both relations, you should add alias.
bucket.Relations.Add(CustomerEntity.Relations.AddressEntityUsingVisitingAddressID, "VisitingAddress");
bucket.Relations.Add(CustomerEntity.Relations.AddressEntityUsingBillingAddressID, "BillingAddress");

// when add the predicate, set the object alias you are filtering on.
bucket.PredicateExpression.Add(
     (AddressFields.City.SetObjectAlias("VisitingAddress")=="Amsterdam")  
     & (AddressFields.City.SetObjectAlias("BillingAddress")=="Rotterdam"));

EntityCollection customers = new EntityCollection(new CustomerEntityFactory());
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntityCollection(customers, bucket);

For more info please read Advance Filtering. Hope that helps.

David Elizondo | LLBLGen Support Team
bjacobs
User
Posts: 73
Joined: 20-Aug-2008
# Posted on: 19-Apr-2009 19:26:04   

That works.

Thanks,

Billy Jacobs