Typed List Child Tables?

Posts   
 
    
Emmet
User
Posts: 36
Joined: 12-Jul-2005
# Posted on: 12-Apr-2007 07:34:01   

Is there a way to create a Typed List or Dynamic List that has a child 1:n relationship?

I know the lists just return a DataTable, but would there be anyway to project a child DataTable into a dataset without another DB call per row?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Apr-2007 09:05:25   

Yes, a TypedList or a DynamicList can hoild fields from diffrent related tables. A JOIN between those tables is performed when fetching the rows.

Emmet
User
Posts: 36
Joined: 12-Jul-2005
# Posted on: 12-Apr-2007 09:17:50   

Walaa wrote:

Yes, a TypedList or a DynamicList can hoild fields from diffrent related tables. A JOIN between those tables is performed when fetching the rows.

As a 1:n collection? Can you show some code, I've been unable to accomplish this.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Apr-2007 09:29:13   

A Typed List is defined in the LLBLGen Pro Designer, please refer to the manual "Using the designer -> Adding typed lists"

For DynamicLists, here is an example (not tested):


// C#
DataAccessAdapter adapter = new DataAccessAdapter();
ResultsetFields fields = new ResultsetFields(3);

fields.DefineField(CustomerFields.FirstName, 0);
fields.DefineField(CustomerFields.LastName, 1);
fields.DefineField(OrderFields.Number, 2);

IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(CustomerEntity.Relations.OrderEntityUsingCustomerId);

DataTable dynamicList = new DataTable();
adapter.FetchTypedList(fields, dynamicList, bucket, 0, null, true, null);

Emmet
User
Posts: 36
Joined: 12-Jul-2005
# Posted on: 12-Apr-2007 09:38:04   

Walaa wrote:

A Typed List is defined in the LLBLGen Pro Designer, please refer to the manual "Using the designer -> Adding typed lists"

For DynamicLists, here is an example (not tested):


// C#
DataAccessAdapter adapter = new DataAccessAdapter();
ResultsetFields fields = new ResultsetFields(3);

fields.DefineField(CustomerFields.FirstName, 0);
fields.DefineField(CustomerFields.LastName, 1);
fields.DefineField(OrderFields.Number, 2);

IRelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(CustomerEntity.Relations.OrderEntityUsingCustomerId);

DataTable dynamicList = new DataTable();
adapter.FetchTypedList(fields, dynamicList, bucket, 0, null, true, null);

Where is the child collection? This just looks like a flat DataTable.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Apr-2007 10:27:59   

Oh, sorry, I misunderstood you, I thought you wanted a flat dataTable.

What you are looking for is available in Entities and EntityCollections, where you can fetch Entities and their related children in 2 queries using PrefetchPaths, rather than a query for each parent entitiy to get its children.

Emmet
User
Posts: 36
Joined: 12-Jul-2005
# Posted on: 12-Apr-2007 11:16:19   

Walaa wrote:

Oh, sorry, I misunderstood you, I thought you wanted a flat dataTable.

What you are looking for is available in Entities and EntityCollections, where you can fetch Entities and their related children in 2 queries using PrefetchPaths, rather than a query for each parent entitiy to get its children.

Ok, so basically if we want a few fields from multiple tables, we have to create new Views in order to maintain Parent -> Child relations. I guess my dilemma is kill flexibility vs. kill performance.

Thanks for the fast response.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Apr-2007 11:27:47   

If you want fields from multiple tables in flattened mannar, you may use a database view, mapped into a TypedView or an entity, you can also use a TypedList which is an Entity View rather than a database view, and you can use a DynamicList defined at runtime. TypedViews, TypedLists and DynamicLists are all DataTables.

If you want to fetch a graph of entities rather than a flat resultset then you should use Entities and PrefetchPaths. You can also create smaller entities (not all fields are mapped) to use in some scenarioes where you don't want to fetch all the fields in the database.