Cannot get prefetch with predicate to work

Posts   
 
    
KennethLu
User
Posts: 5
Joined: 25-Aug-2006
# Posted on: 25-Aug-2006 21:07:43   

Hi there,

We are using .NET 1.1 generated code and we cannot get prefetch to work. I looked into the query that was executed and the query does not join the 2 tables. It just selects from the "Products" table. Any help would be greatly appreciated.

Our 2 tables:

We have a "products" table and a "ProductCat2" table (product categories). So basically we would like to know which categories each product belongs to.

Our code:

ProductsCollection products = new ProductsCollection(); ProductsEntity product = new ProductsEntity(); IPrefetchPath prefetchpath = new PrefetchPath(product.LLBLGenProEntityTypeValue); prefetchpath.Add(ProductsEntity.PrefetchPathProductCat2); filters = new PredicateExpression(); filters.Add(ProductCat2Fields.Parent != "Parts"); products.GetMulti(filters, prefetchpath);

Result:

We basically get an error. In the query that was executed, the query does not select from the "ProductCat2" table. Did we do anything wrong? We are using Access, if that matters. Thank you in advance.

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 25-Aug-2006 21:20:55   

Hey Kenneth,

The filter needs to be added to the prefetch path at the level where you want the filtering.

I don't have a Self-Servicing project I can check syntax on, but it should be something like:


//create filter before you add it to the prefetch path
filters = new PredicateExpression();
filters.Add(ProductCat2Fields.Parent != "Parts");

ProductsCollection products = new ProductsCollection();
ProductsEntity product = new ProductsEntity();
IPrefetchPath prefetchpath = new PrefetchPath(product.LLBLGenProEntityTypeValue);

//I assume you want this portion of the prefetch filtered--check the overloads to make
//sure this is correct
prefetchpath.Add(ProductsEntity.PrefetchPathProductCat2, 0, filter);

//also, don't pass the filter in here--I'm not sure what the overloads for 
//GetMulti look like, so this might be slightly off
products.GetMulti(prefetchpath);

HTH,

Phil

KennethLu
User
Posts: 5
Joined: 25-Aug-2006
# Posted on: 25-Aug-2006 22:10:50   

Cool! It worked! Thank you very much for your help!

I did not understand the subtleties of the example given in the help doc. Thanks, again. simple_smile