Typed lists and children collections?

Posts   
 
    
Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 29-Sep-2007 15:48:52   

This is regarding typed lists.

If I have a table that looks like this: Article - ID int identity - Parent_ID int (FK to ID) - Lots of other stuff

Can I get LLBLGen to generate a typed list that will look something like this class Article - int id - TypedListCollection<Article> Children

I know I can do it with regular entities, but I need it to be done using typed list. If not, would it be doable using a typed view (doubt it myself)?

Posts: 254
Joined: 16-Nov-2006
# Posted on: 29-Sep-2007 23:45:50   

I'm unclear why your trying to do this as the generated Article entity should have a method such as GetMultiArticle to retrieve all the articles ( children ) associated with the article.

Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 30-Sep-2007 01:41:01   

The articles table has about 20 relations, and I need to display some, not all, data from every relation in in a grid.

I'd ideally want to create a view that has those fields, which I can. Except for that pesky child collection problem. I could return a count of the number of children and do a just-in-time fetch of the children when the grid needs them, but I'd rather have them loaded when loading the rest of the data.

That is why I'm trying to do this. I do realize I'll probably end up doing what I said above, but one can always hope...

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 30-Sep-2007 05:58:49   

i would create a typedlist fetch for the parent and each child collection. part of the filter of each child collection would contain the FK ids to the articles. then create a dataset with data table relations. something like this

DataTable article = new DataTable();
DataTable children = new DataTable();

//construct article typedlist fields, relations, filter, sort
adapter.FetchTypedList(article...);

List<int> articleIds = new List<int>();
foreach(DataRow row in article.Rows)
{
   articleIds.Add((int)row["ArticleId"]);
}

//construct children typedlist fields, relations, filter, sort
// childrenFields.ArticleId = articleIds
adapter.FetchTypedList(children...);

DataSet ds = new DataSet();
ds.Tables.Add(article);
ds.Tables.Add(children);
ds.Relations.Add(new DataRelation(article to children));

return ds;

Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 30-Sep-2007 14:51:12   

That might work, but... Is there any way of doing that using the actual generated typed list objects, instead of datatables and datasets?

And a related question, is there an IEntityFields2 "collection" generated for each entity and typed list somewhere?

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 30-Sep-2007 21:19:11   

typedlists are lightweight wrappers around datatables. you could create a strongly typed dataset. just make sure the typedlist field names match the datatable column names.

Typedlists are flat tables. there is not a graph without building one yourself (dataset with relations).

In v2.5 there is a "fetch graph as dataset" functionality. I haven't spent any time with the new version so I'm not sure how it works with aggregates or excluded fields.

Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 01-Oct-2007 08:41:36   

Thanks for your help. Ended up loading the view as an entity, and then added a child collection to it manually in code.

Since its read only and wont ever need to perform a save/update it should work, and if I get performance issues down the road I'll fix it then. Premature optimization is evil stuck_out_tongue_winking_eye