adding a relations collection to a typedList (via code)

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 20-Apr-2007 20:36:55   

version 1.0.2005.1 final (self-servicing) VS2005 asp.net 2.0


hiya,

I have a typed list that I need to filter via a predicate. In order for this predicate to work, I believe I need a relations collection.

I have successfully built the predicate and relationsCollection.However, I can't see any oveload that will allow me to add the relations Collection to the predicate.

Essentially, I am trying to grab a all the products that have a categoryId of "1" in the mapped table.


RelationCollection relationsToUse = new RelationCollection(); 
       relationsToUse.Add(dalHamilton.EntityClasses.CskStoreProductEntity.Relations.CskStoreProductCategoryMapEntityUsingProductId);

IPredicateExpression filtProductCategory = new PredicateExpression();
filtProductCategory.Add(CskStoreProductCategoryMapFields.CategoryId == 1);

dalHamilton.TypedListClasses.TListPromoProductsTypedList tListPromoProducts = new TListPromoProductsTypedList();

tListPromoProducts.Fill(20, null, false, filtProductCategory) ; //??HOW DO I ADD the relationsCollection?

many thanks,

yogi

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Apr-2007 04:53:47   

Hi yogi,

You can use GetMultiAsDataTable() as follows:

MyTypedList myTL = new MyTypedList();
IRelationCollection relations = myTL.BuildRelationSet();
relations.Add(/*the needed relation*/);

TypedListDAO dao = DAOFactory.CreateTypedListDAO();
dao.GetMultiAsDataTable(myTL.BuildResultset(), myTL, 0, null, /*needed filter*/, relations, false, null, null, 0, 0); 
David Elizondo | LLBLGen Support Team
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 22-Apr-2007 19:26:43   

Hiya David.

Thanks for that.Here’s the code that I used, in case anyone wants it.

dalHamilton.TypedListClasses.TListPromoProductsTypedList tListPromoProducts = new TListPromoProductsTypedList();

IRelationCollection relationsToUse = tListPromoProducts.BuildRelationSet();
        relationsToUse.Add(dalHamilton.EntityClasses.CskStoreProductEntity.Relations.CskStoreProductCategoryMapEntityUsingProductId);

TypedListDAO dao = DAOFactory.CreateTypedListDAO();
dao.GetMultiAsDataTable(tListPromoProducts.BuildResultset(), tListPromoProducts, 3, null, filtProductCategory, relationsToUse, false, null, null, 0, 0); 
            
dListProducts.DataSource =  tListPromoProducts;  
dListProducts.DataBind();

Cheers,

yogi