add additional fields (from a "parent" table) to entityCollection

Posts   
 
    
yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 17-Aug-2007 11:33:37   

asp.net 2.0 llblgenpro 2 adapterTemplate

Hiya,

I am binding a datalist to an entityCollection “jobItemEntityCollection”.

However, I want to include additional fields that are not directly contained in this entityCollection.I want to include a field “jobName” field, that is actually contained in a “parent” table.

Schema below:

tblJob   //parent table
jobId     (PK)
jobName   //value that I want to include in my jobItem entityCollection

tblJobItem
jobItemId   (PK)
jobId         (FK  -->  tblJob.JobId)

I hope that I’ve explained the above clearly.

My questions:

1 should I be using the jobItem entityCollection / some other approach?

2 If I should be using the jobItem entityCollection, how do I add the additional field from the parent table.

As always, many thanks.

yogi sunglasses

Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 17-Aug-2007 12:32:21   

a) If I'm doing a listing page I will create a typelist that has the fields from the child table and the required fields from the parent table.

b) If I'm doing a details page, I would tend to grab the child entity and use a prefetch path to get the parent entity.

Note: You should be able to use the prefetch path approach for a) but it *seems" less efficient than b). I think you can then access the field using something similar to the following

<%# Eval("childitem.parentfield") %>

Erm ... I think flushed

Pete

note: syntax updated based on note from walaa.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 17-Aug-2007 15:17:45   

You should be able to access a property in a related entity as follows:

'<%# DataBinder.Eval(Container.DataItem, "Job.JobName")%>'

Provided that you use a prefetchPath to fetch the related entity (Job entity).

Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 18-Aug-2007 23:32:27   

Thanks for correcting my syntax walaa.

Pete

yogiberr
User
Posts: 432
Joined: 29-Jun-2005
# Posted on: 21-Aug-2007 13:24:28   

ta for the help lads,

this is the code, incase it can help anyone:

EntityCollection jobItems = new EntityCollection(new JobItemEntityFactory());
        IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.JobItemEntity);
        prefetchPath.Add(JobItemEntity.PrefetchPathJob);
        DataAccessAdapter adapter = new DataAccessAdapter();
        adapter.FetchEntityCollection(jobItems, null, prefetchPath);

yogi sunglasses