+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Get Parent and Child objects from a query

Get Parent and Child objects from a query

2 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    26 Oct 2010
    Link to this post
    Hi Team
    I have problems to get my relationed objects in a Dataset or IList from a query including the childs objects (1:1) building a Module. I have added a sample of Product / ProductDetail /ProductImages. I need to query Product based on ProductsDetails.Price or Product.Quality and get all items loaded including childs object in a Dataset or IList to expose.
    How to get in DataSet or IList object from the query ?:
    like -> Name | ProductDetail_lnk.Price | ProductDetail_lnk.Quality

    Product
    {
      Name;
      link ProductDetail_lnk;
    }
    ProductDetail
    {
      Price;
      Quality;
      relation ProductImages_lnk;
    }
    ProductImages
    {
      Image;
      Data;
      link ProductDetail;
    }
    rel : Product 1:1 ProductDetail 1:n ProductImages

    QueryProduct q=new QueryProduct();
    q.AndCondition("Name", QueryCondition.EQ, "valueName");//from level1
    q.AndCondition("ProductDetail_lnk.Quality", QueryCondition.EQ, "valueQuality");//from level2
    q.AndCondition("ProductDetail_lnk.ProductImages_lnk.Data", QueryCondition.LE, "valueData");//from level3
    q.LoadAll();
    GroupSerialize gs = new GroupSerialize();
    gs.Add(q);
    DataTable dt=gs.Data.Table[0];  <-- Passing only Parents objects level1?

    Thanks.
  2. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    28 Oct 2010
    Link to this post
    Umm, nobody.

    I have partially solved passing in the same GroupSerializer 3 queries from Product, ProductDetail and ProductImages to get a Dataset with 3 tables like :

    GroupSerilalizer gs=new GroupSerializer();
    -->Query1 Products including q1.Grouped="MyGroup";
    gs.Add(q1);
    -->Query2 ProductsDetail by ProductID
    gs.Add(q2);
    -->Query(q3) ProductsImages by ProductID
    gs.Add(q3);
    DataSet ds=gs.Data;(3 tables no relation)

    But it's a very large amount of code. Normally using lazy loaded objects in the query1 i can get the linked objects q1[0].Product_lnk.Price but are not passed to the serializer. Can someone explain how to passing the linked objects using Actions or recursive queries in nolics ?.

    Product 1---1 ProductDetail 1---N ProductImages

    cheers.
2 posts, 0 answered