Multiple Entity Filtering Question

Posts   
 
    
UncleT
User
Posts: 6
Joined: 13-Oct-2006
# Posted on: 13-Oct-2006 13:17:06   

Using LLBLGen 2.0.0.0 Final demo, Self servicing, .net 1.1, vs2003

Forgive me if I’m going about this the wrong way but I am new to LLBLGEN. I’m having trouble filtering using the predicate and relationship functionality. Please could someone give me some pointers.

My test database contains the following tables and relationships:

PROVIDER (fields: ID) PROVIDERINFO (fields: ID(pk), ProviderId, Name) PRODUCT (fields: ID, ProviderId) PRODUCTINFO (fields: ID(pk), ProductId, Name)

PROVIDER has a 1:n relationship with both PROVIDERINFO and PRODUCT (fk= ProviderId in each case) PRODUCT has a 1:n relationship with PRODUCTINFO (fk=ProductId)

I need to create a filter that returns a PRODUCT Collection for all PRODUCT entries where PRODUCTINFO.Name=”UncleT” and PROVIDERINFO.NAME=”me”

So, my code needs to be something like...


ProductCollection products=new ProductCollection();
PredicateExpression predicate=new PredicateExpression();
RelationshipCollection relations=new RelationshipsCollection();

relations.Add(ProductEntity.Relations.ProductInfoUsingProductId,"Alias_ProductInfo");
predicate.Add(ProductInfo.Name.SetObjectAlias("Alias_ProductInfoA ") ==”UncleT”);

relations.Add(ProductEntity.Relations.ProviderUsingProviderId & ProviderEntity.Relations.ProviderInfoUsingProviderId,”Alias_ProviderInfo”);
predicate.AddWithAnd(ProviderInfo.Name. SetObjectAlias("Alias_ProviderInfo") == “me”);

products.GetMulti(predicate,0,null,relations);

...but you can't add multiple relationships under a single alias as I have done above, so how should I create a predicate expression where each predicate uses different sets of relationships? confused

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Oct-2006 15:39:09   

Please try the following code:


ProductCollection products = new ProductCollection();
PredicateExpression predicate = new PredicateExpression();
RelationshipCollection relations = new RelationshipsCollection();

relations.Add(ProductEntity.Relations.ProductInfoUsingProductId);
predicate.Add(ProductInfoFields.Name ==”UncleT”);

relations.Add(ProductEntity.Relations.ProviderUsingProviderId); 
relations.Add(ProviderEntity.Relations.ProviderInfoUsingProviderId);
predicate.Add(ProviderInfoFields.Name == “me”);

products.GetMulti(predicate,0,null,relations);

UncleT
User
Posts: 6
Joined: 13-Oct-2006
# Posted on: 13-Oct-2006 16:14:55   

oops!! I had tried that before but something else was wrong in my code flushed Sorry for wasting your time but thanks for saving mine!