Databinding BinaryComponents.SuperList

Posts   
 
    
Velocis
User
Posts: 3
Joined: 19-Nov-2008
# Posted on: 19-Nov-2008 20:10:56   

Hi,

I'm new to LLBLGen and I'm trying to bind a custom WinForms GridView using EntityCollection. The binding works well if I don't use any related datafields. But the related fields needed to be fetched. How do I achieve this?


RelationPredicateBucket filterBucket = new RelationPredicateBucket();
DataAccessAdapter adapter = new DataAccessAdapter();
EntityCollection entities = new EntityCollection(new JobsEntityFactory());
adapter.FetchEntityCollection(entities, filterBucket);

I need to get the related entities too fetched with that collection.


listJobs.Columns.Add(new Column("Client", "Client", 120, delegate(object item) { return ((JobsEntity)item).Clients.ClientName; })); // this is null as it's not fetched yet.

I do realise that I can iterate the entitycollection and fetch the related client individually, but that doesn't sound right to me.

Please advice.

Cheers, Ganesh

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Nov-2008 03:11:04   

Hi Ganesh,

You need to use PrefetchPaths here. Your code should looks like:

RelationPredicateBucket filterBucket = new RelationPredicateBucket();
PrefetchPath2 path = new PrefetchPath((int) EntityType.JobsEntity);
path.Add(JobsEntity.PrefethPathClientEntityUsingClientId);
DataAccessAdapter adapter = new DataAccessAdapter();
EntityCollection entities = new EntityCollection(new JobsEntityFactory());
adapter.FetchEntityCollection(entities, filterBucket, path);

Example of complex prefetchPath scenarios: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=9264&StartAtMessage=0&#51656

Hope helpful simple_smile

David Elizondo | LLBLGen Support Team
Velocis
User
Posts: 3
Joined: 19-Nov-2008
# Posted on: 20-Nov-2008 06:23:52   

daelmo wrote:

Hi Ganesh,

You need to use PrefetchPaths here. Your code should looks like:

RelationPredicateBucket filterBucket = new RelationPredicateBucket();
PrefetchPath2 path = new PrefetchPath((int) EntityType.JobsEntity);
path.Add(JobsEntity.PrefethPathClientEntityUsingClientId);
DataAccessAdapter adapter = new DataAccessAdapter();
EntityCollection entities = new EntityCollection(new JobsEntityFactory());
adapter.FetchEntityCollection(entities, filterBucket, path);

Example of complex prefetchPath scenarios: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=9264&StartAtMessage=0&#51656

Hope helpful simple_smile

Hi David,

That worked like a charm! Thank you very much. There was a typo though.

PrefetchPath2 path = new PrefetchPath((int) EntityType.JobsEntity);

This was missing a "2". Corrected this to:

PrefetchPath2 path = new PrefetchPath2((int) EntityType.JobsEntity);

I also noticed another thing.

path.Add(JobsEntity.PrefethPathClientEntityUsingClientId);

I didnt find PrefethPathClientEntityUsingClientId in the list but did find PrefethPathClients in it. Is it because the foreign key field was a primary key?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Nov-2008 07:39:52   

Yes I was just guessing your structure. But you got the point simple_smile

Cheers

David Elizondo | LLBLGen Support Team
Velocis
User
Posts: 3
Joined: 19-Nov-2008
# Posted on: 20-Nov-2008 07:44:32   

daelmo wrote:

Yes I was just guessing your structure. But you got the point simple_smile

Cheers

Fantastic! Thanks a lot, mate simple_smile