Fetching an EntityCollection

Posts   
 
    
graphicsxp
User
Posts: 7
Joined: 14-Aug-2008
# Posted on: 14-Aug-2008 11:25:38   

Hello,

I'm very new to LLBLGen. I have created a project from two tables, each coming from a separate catalog within the same sqlserver.

[Cutting] has a foreign key called PublicationID which links to the primary key PublicationID of the [Publication] table. (again they are in separate catalogs).

I've created the above association before I generated the code.

Now what I would like to do should be really simple, but I just can't figure it out. I want to fetch the first 10 records of my [Cutting] table into a EntityCollection and each Cutting entity should contain its associated Publication entity.

Here's my code so far :


DataAccessAdapter db = new DataAccessAdapter();
db.ConnectionString = 'my connection string'

EntityCollection<CuttingEntity> cuttings = new EntityCollection<CuttingEntity>();

So I don't know how to populate my EntityCollection. I've looked at FetchEntityCollection but was not really inspired by it...

Please can you help me getting started ?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Aug-2008 12:22:16   

Is the relation between these entities realized in the LLBLGen Pro Designer, if not you may create a custom relation in the Designer.

Then you should use a PrefetchPath to fetch the related entities, please check the docs for Generated code - Prefetch Paths

graphicsxp
User
Posts: 7
Joined: 14-Aug-2008
# Posted on: 14-Aug-2008 13:01:10   

Walaa wrote:

Is the relation between these entities realized in the LLBLGen Pro Designer, if not you may create a custom relation in the Designer.

Then you should use a PrefetchPath to fetch the related entities, please check the docs for Generated code - Prefetch Paths

I've found out how to get my records :

EntityCollection<CuttingEntity> cuttings = new EntityCollection<CuttingEntity>();

      RelationPredicateBucket filter = new RelationPredicateBucket(CuttingFields.DateCreated > @"13 jul 2008");
      db.FetchEntityCollection(cuttings, filter);

      return cuttings;

I get 2500 results and the problem is that when the function returns, my cpu just go mad and i never receive the results on the client side. I think this is because of all the associations on the [Cutting] table. Is there something I'm doing wrong ?

Regarding your question about the relation between my entities, I think I've created it them from the Designer by clicking the Relation node and choosing Add new 1:1 relation

graphicsxp
User
Posts: 7
Joined: 14-Aug-2008
# Posted on: 14-Aug-2008 13:15:01   

I see, it looks like I need pre-fetch functionnality. However I'm not using SelfServicing and I want to keep using DataAccessAdapter, so how can I go around this issue ?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Aug-2008 13:30:12   

PrefetchPaths are available for both models.

Please check Generated code - Prefetch paths, Adapter

graphicsxp
User
Posts: 7
Joined: 14-Aug-2008
# Posted on: 14-Aug-2008 16:53:26   

Ok, I've used PrefetchPath2 and yet I'm still having the same performance issue. If I retrieve just one cutting (like below) it works, but if the collection contains hundreds of cuttings then it my CPU goes mad and nothing is never returned.

I've used prefetch on all the tables in my relations.

EntityCollection<CuttingEntity> cuttings = new EntityCollection<CuttingEntity>();

  IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.CuttingEntity);
  prefetchPath.Add(CuttingEntity.PrefetchPathCuttingFlag);
  prefetchPath.Add(CuttingEntity.PrefetchPathCuttingOrganisation).SubPath.Add(CuttingOrganisationEntity.PrefetchPathCuttingOrgFlag);
  prefetchPath.Add(CuttingEntity.PrefetchPathPublication);

  RelationPredicateBucket filter = new RelationPredicateBucket(CuttingFields.CuttingId == 1);
  //db.FetchEntityCollection(cuttings, filter);
  db.FetchEntityCollection(cuttings, filter, prefetchPath);
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Aug-2008 05:48:19   

At this link scroll down to Optimizing Prefetch Paths and evaluate whether you need to use ParameterisedPrefetchPathThreshold.

David Elizondo | LLBLGen Support Team