binding entitycollection with relations to datagridview

Posts   
 
    
c_pousson
User
Posts: 12
Joined: 03-Jul-2008
# Posted on: 03-Jul-2008 16:33:46   

Hi, I am very new to LLBLGen and we decided to use it for our newest project at work. I have some code that creates a collection:


EntityCollection<WaterwayEntity> waterwayCollection = new EntityCollection<WaterwayEntity>(new WaterwayEntityFactory());
RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(WaterwayEntity.Relations.LocationEntityUsingLocationID, JoinHint.Inner);
PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.WaterwayEntity);
prefetch.Add(WaterwayEntity.PrefetchPathLocation);
DataAdapter.FetchEntityCollection(waterwayCollection,null,0,null,prefetch);
            
return waterwayCollection;

then I set the set the datasource of the datagridview to this collection and it shows the rows with the corresponding ID's but not the relational field from the Location table that describes the location based on the ID.

When I look at the rows that are held in the entitycollection I see that it contains all the fields and there corresponding values except the Location field(which is the only field from the relational bucket) I see it as EntityClasses.LocationEntity. how do I get this bound with the rest of the data? Thanks in advance.

c_pousson
User
Posts: 12
Joined: 03-Jul-2008
# Posted on: 03-Jul-2008 19:08:39   

I realized that my last post was a bit ambiguous so let me clarify.

2 tables

waterway: waterwayID LocationID ...

Location LocationID Description ...

the code:


EntityCollection<WaterwayEntity> waterwayCollection = new EntityCollection<WaterwayEntity>(new WaterwayEntityFactory());
RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(WaterwayEntity.Relations.LocationEntityUsingLocationID, JoinHint.Inner);
PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.WaterwayEntity);
prefetch.Add(WaterwayEntity.PrefetchPathLocation);
DataAdapter.FetchEntityCollection(waterwayCollection,null,0,null,prefetch);
            
return waterwayCollection;

so I have an entity collection that also gets the location description by the LocationID using the relation

after fetching the entity collection I have several Items WaterwayID = 1 LocationID = 1 Location = [EntityClasses.Location]

now when I bind this to a dgv I see the WaterwayID and LocationID but not the Location. There is not even a column header for it.

Any ideas

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 04-Jul-2008 11:18:12   

Location is not an entityField inside the Waterway entity, but it's a field mapped to the related entity.

Normally you'd want to display a field or a couple of fields from the related entity, not the entire entity object.

Now if for example you want to display Location.Name you have the following options:

1- Handle some datagridView event (eg. RowsAdded or CellFormatting), to manually grab data from the bound related entity and insert it in the specified column.

2- Use a flat object (DynamicList or a TypedList), which is used to display fields from multiple related entities, but in a read-only fashion.

3- Use the Designer to create a "field on related field" (eg. LocationName) in the waterway entity, which gets populated by the prefetchPath call.

4- In web apps (for reference), you can bind to a related field with the following code:

<%# DataBinder.Eval(Container.DataItem, "Location.Name") %>

Also please check the following thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=9384