Large Prefetch that I can't seem to get working

Posts   
 
    
snowball
User
Posts: 19
Joined: 08-Mar-2007
# Posted on: 08-Mar-2007 18:40:34   

(Would you be so kind next time to add some spaces so the layout of the forum isn't destroyed? simple_smile Thanks -- Otis)

I have a large prefetch that I am having problem getting is to work. I have a entity called ListHeaderEntity and from that 3 main detail entities which branch out to other entites.

The 3 subentites are ListHeaderNameCategories ListHeaderBranchCategories ListHeaderContactCategories

All 3 entites branch out to other entities. Here is what my code looks like.

    internal ListHeaderEntity GetListHeader(ListHeaderEntity entity, ListHeaderFacade.Options options)
    {
        PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.ListHeaderEntity);

        prefetch.Add(ListHeaderEntity.PrefetchPathReps);
        prefetch.Add(ListHeaderEntity.PrefetchPathCurentReps);
        prefetch.Add(ListHeaderEntity.PrefetchPathComments);
        prefetch.Add(ListHeaderEntity.PrefetchPathPrePayments);

        if (options.IncludeDetails)
        {
            // Get Name Categories entities
            prefetch.Add(ListHeaderEntity.PrefetchPathNameCategories);

            IPrefetchPathElement2 prefetchPathElement1 = ListHeaderEntity.PrefetchPathNameCategories;

            prefetchPathElement1.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderNameCategories)

.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineBranches).SubPath.Add( ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchAdditionals).SubPath.Add( ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchContacts).SubPath.Add( ListDetailRcLineDetBranchDetContactEntity.PrefetchPathRclineDetBranchDetContactAdditionals); prefetchPathElement1.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderNameCategories) .SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineContacts).SubPath.Add( ListDetailRcLineDetContactEntity.PrefetchPathRclineDetContactAdditionals); prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdditionals); prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdjustments); prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineInserts); prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineSpecs); prefetch.Add(prefetchPathElement1);

            // Get Contact Categories entities
            prefetch.Add(ListHeaderEntity.PrefetchPathContactCategories);

            IPrefetchPathElement2 prefetchPathElement2 = ListHeaderEntity.PrefetchPathContactCategories;

            prefetchPathElement2.SubPath.Add(ListDetailEntity..PrefetchPathListHeaderContactCategories) .SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineBranches).SubPath.Add( ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchAdditionals).SubPath.Add( ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchContacts).SubPath.Add( ListDetailRcLineDetBranchDetContactEntity.PrefetchPathRclineDetBranchDetContactAdditionals);
            prefetchPathElement2.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderContactCategories) .SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineContacts).SubPath.Add( ListDetailRcLineDetContactEntity.PrefetchPathRclineDetContactAdditionals);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdditionals);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdjustments);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineInserts);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineSpecs);
            prefetch.Add(prefetchPathElement2);

            // Get Branch Categories entities
            prefetch.Add(ListHeaderEntity.PrefetchPathBranchCategories);

            IPrefetchPathElement2 prefetchPathElement3 = ListHeaderEntity.PrefetchPathBranchCategories;

            prefetchPathElement3.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderBranchCategories) .SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineBranches).SubPath.Add( ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchAdditionals).SubPath.Add( ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchContacts).SubPath.Add( ListDetailRcLineDetBranchDetContactEntity.PrefetchPathRclineDetBranchDetContactAdditionals);
            prefetchPathElement3.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderBranchCategories) .SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineContacts).SubPath.Add( ListDetailRcLineDetContactEntity.PrefetchPathRclineDetContactAdditionals);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdditionals);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdjustments);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineInserts);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineSpecs);
            prefetch.Add(prefetchPathElement3);
        }

        DBActionResult result = base.FetchEntity(entity, prefetch);
        return (entity);
    }

Your help will be very helpful,

Thanks Snowball

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Mar-2007 23:16:15   

At this lines,

prefetchPathElement1.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderNameCategories).SubPath.Add(... 
prefetchPathElement1.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderNameCategories).SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineContacts)....

You would recieve an ArgumentException: The PrefetchPathElement you to tried to add is already added to this PrefetchPath.disappointed

This is because you are adding _PrefetchPathListHeaderNameCategories _twice to prefetchPathElement1. You need create another _IPrefetchPathElement2 _(say subPath1) which would have all necessary subpaths added, then you add _suPath1 _to your _prefetchPathElement1 _only once.

The same would be revised in all your code. wink

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 09-Mar-2007 11:26:14   

Also, what exactly is the problem? What exactly doesn't work?

Frans Bouma | Lead developer LLBLGen Pro
snowball
User
Posts: 19
Joined: 08-Mar-2007
# Posted on: 10-Mar-2007 04:30:21   

Here’s an example of my layout. I understand why I am getting the error message “Prefetch already added” my problem is that I am not sure how to get around this problem.

As you can see from my below layout I have a ListHeaderNameCategroryEntity, ListHeaderBranchCategoryEntity and ListHeaderContactEntity. Each of these entities related to the ListDetailEntity, ListDetailRclineEntity etc.

How can I build this “Prefetch” to make sure that the ListHeaderNameCategoryEntity, ListHeaderBranchCategory and ListHeaderContactCategoryEntity are all related to there own data structure.

I hope this information is helpful. I have also change my previous code Thanks for you help.

ListerHeaderEntity

ListHeaderNameCategoryEntity
 ListDetailEntity

   ListDetailRclineEntity

         ListDetailRclineBranchEntity
             ListDetailRclineBranchDetEntity
                 ListDetailRclineDetailBranchContactEntity
                     ListailRclineDetailBranchDetailContactEntity

             ListDetailRclineContactEntity
                 ListDetailDetailDetailContactEntity

ListHeaderBranchCategoryEntity ListDetailEntity

     ListDetailRclineEntity

         ListDetailRclineBranchEntity
             ListDetailBranchDetEntity
                 ListDetailRclineDetailBranchContactEntity
                     ListDetailRclineDetailBranchDetailContactEntity

                 ListDetailRclineContactEntity
                     ListDetailDetailDetailContactEntity


ListHeaderContactCategoryEntity

ListDetailEntity

     ListDetailRclineEntity

         ListDetailRclineBranchEntity
            ListDetailRclineBranchDetEntity
                ListDetailRclineDetailBranchContactEntity
                    ListDetailRclineDetailBranchDetailContactEntity

            ListDetailRclineContactEntity
                ListDetailDetailDetailContactEntity

internal ListHeaderEntity GetListHeader(ListHeaderEntity entity, ListHeaderFacade.Options options) { PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.ListHeaderEntity);

        prefetch.Add(ListHeaderEntity.PrefetchPathReps);
        prefetch.Add(ListHeaderEntity.PrefetchPathCurentReps);
        prefetch.Add(ListHeaderEntity.PrefetchPathComments);
        prefetch.Add(ListHeaderEntity.PrefetchPathPrePayments);

        if (options.IncludeDetails)
        {
            **// Get Name Categories entities ****(ListHeaderNameCategoryEntity)**
            prefetch.Add(ListHeaderEntity.PrefetchPathListHeaderNameCategory);

            IPrefetchPathElement2 prefetchPathElement1 = ListHeaderEntity.PrefetchPathListHeaderNameCategory);

(ListDetailEntity) prefetchPathElement1.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderNameCategories); prefetchPathElement1.SubPath.Add(ListDetailEntity.PrefetchPathListDetailRcLines);

            // Branches with Name Categories
            prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineBranches);
            prefetchPathElement1.SubPath.Add(ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchAdditionals);
            prefetchPathElement1.SubPath.Add(ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchContacts);
            prefetchPathElement1.SubPath.Add(ListDetailRcLineDetBranchDetContactEntity.PrefetchPathRclineDetBranchDetContactAdditionals);

            //Contacts within Name Categories
            prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineContacts);
            prefetchPathElement1.SubPath.Add(ListDetailRcLineDetContactEntity.PrefetchPathRclineDetContactAdditionals);

            prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdditionals);
            prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdjustments);
            prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineInserts);
            prefetchPathElement1.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineSpecs);
            prefetch.Add(prefetchPathElement1);


            **// Get Branch Categories entities ****(ListHeaderBranchCategoryEntity)**
            prefetch.Add(ListHeaderEntity.PrefetchPathListHeaderBranchCategory);

            IPrefetchPathElement2 prefetchPathElement2 = ListHeaderEntity.PrefetchPathListHeaderBranchCategory);
            prefetchPathElement2.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderBranchCategories);
            prefetchPathElement2.SubPath.Add(ListDetailEntity.PrefetchPathListDetailRcLines);

            // Branches with Name Categories (ListDetailRclineBranchEntity)
            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineBranches);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchAdditionals);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchContacts);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineDetBranchDetContactEntity.PrefetchPathRclineDetBranchDetContactAdditionals);

            //Contacts within Name Categories  (ListDetailRclineContactEntity)
            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineContacts);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineDetContactEntity.PrefetchPathRclineDetContactAdditionals);

            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdditionals);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdjustments);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineInserts);
            prefetchPathElement2.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineSpecs);
            prefetch.Add(prefetchPathElement2);


        ** // Get Contact Categories entities ****(ListHeaderContactCategoryEntity)**
            prefetch.Add(ListHeaderEntity.PrefetchPathListHeaderBranchCategory);

            IPrefetchPathElement2 prefetchPathElement3 = ListHeaderEntity.PrefetchPathListHeaderBranchCategory);
            prefetchPathElement3.SubPath.Add(ListDetailEntity.PrefetchPathListHeaderBranchCategories);
            prefetchPathElement3.SubPath.Add(ListDetailEntity.PrefetchPathListDetailRcLines);

            // Branches with Name Categories
            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineBranches);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchAdditionals);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineDetBranchEntity.PrefetchPathRclineDetBranchContacts);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineDetBranchDetContactEntity.PrefetchPathRclineDetBranchDetContactAdditionals);

            //Contacts within Name Categories
            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineContacts);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineDetContactEntity.PrefetchPathRclineDetContactAdditionals);

            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdditionals);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineAdjustments);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineInserts);
            prefetchPathElement3.SubPath.Add(ListDetailRcLineEntity.PrefetchPathRclineSpecs);
            prefetch.Add(prefetchPathElement3);         }
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Mar-2007 03:24:49   

As I see there are three base scenarios to use the PrefethPath, and others can extended if you need that:

Having a IPrefetchPath2 rootPath = new PrefetchPath2((int) myRootEntity)...

1. Adding a leaf:

rootPath.Add(myRootEntity.PrefetchPathMyA);

2. Adding a branch that have one leaf you want to add.

rootPath.Add(myRootEntity.PrefetchPathMyA)
     .SubPath.Add(MyAEntity.PrefetchPathMyA1) ;

3. Adding a branch that have two or more leafs you want to add.

// the branch to add
IPrefetchPathElement2 branchPath = myRootEntity.PrefetchPathMyA;
brachPath.Add(MyAEntity.PrefetchPathMyA1);
brachPath.Add(MyAEntity.PrefetchPathMyA2);
brachPath.Add(MyAEntity.PrefetchPathMyA3);
//... so on

// adding the branch
rootPath.Add(branchPath);

And examples of extended scenarios:

4. Adding a branch that have other branch that have one leaf you want to add (2 extended).

rootPath.Add(myRootEntity.PrefetchPathMyA)
     .SubPath.Add(MyAEntity.PrefetchPathMyA1)
          .SubPath.Add(MyA1Entity.PrefetchPathMyA11);
               // ... so on

5. Adding a branch that have two or more leafs and one leaf is a branch that have other leaf you want to add. (1, 2 and 3 mixed)

// the branch to add
IPrefetchPathElement2 branchPath = myRootEntity.PrefetchPathMyA;
brachPath.Add(MyAEntity.PrefetchPathMyA1)
     .SubPath.Add(MyAEntity.PrefetchMyA11);
brachPath.Add(MyAEntity.PrefetchPathMyA2);
brachPath.Add(MyAEntity.PrefetchPathMyA3);
//... so on

// adding the branch
rootPath.Add(branchPath);

6. Adding a branch that have two or more leafs and one leaf is a branch that have two or more leafs you want to add. (3 extended)


// subbranch to add
IPrefetchPathElement2 subBranchPath = PrefetchPathMyA.PrefetchPathMyA1;
subBranchPath.Add(MyA1Entity.PrefetchPathMyA11);
subBranchPath.Add(MyA1Entity.PrefetchPathMyA12);
subBranchPath.Add(MyA1Entity.PrefetchPathMyA13);

/// the branch to add
IPrefetchPathElement2 branchPath = myRootEntity.PrefetchPathMyA;
// here the subBranch, this way you can add multiples subPaths.
brachPath.Add(subBranchPath);
brachPath.Add(MyAEntity.PrefetchPathMyA2);
brachPath.Add(MyAEntity.PrefetchPathMyA3);
//... so on

// adding the branch to the rootPath
rootPath.Add(branchPath)

You can mix the scenarios as you need, the thing is that you can't use SubPath twice for the same base Entity, for example

roorPath.Add(MyAEntity.PrefetchPathA1);
roorPath.Add(MyAEntity.PrefetchPathA2);

Instead of that, you can create a IPrefetchElement to add the two SubPaths once to the root branch.

If you experience problems applying these scenarios to your code, let us know. wink

David

David Elizondo | LLBLGen Support Team
snowball
User
Posts: 19
Joined: 08-Mar-2007
# Posted on: 12-Mar-2007 07:41:15   

Hi David,

Thanks for your great examples. This is where I am running into problems.

Base on example 6. I added 2 new subBranches. subBranchPath2 and subBranchPath3 letters "B" and "C".

Adding **subBranchPath **to the branchPath works great but how can I add subBranchPath2 to myRootEntity.PrefetchPathMyB if I am not allow to add the same subPath more then once to the base Entity.

1. Your example code


// subbranch to add
IPrefetchPathElement2 subBranchPath = PrefetchPathMyA.PrefetchPathMyA1;
subBranchPath.Add(MyA1Entity.PrefetchPathMyA11);
subBranchPath.Add(MyA1Entity.PrefetchPathMyA12);
subBranchPath.Add(MyA1Entity.PrefetchPathMyA13);

2. New Code that I have added. I created a subBranchPath2 and subBranchPath3


// subbranch 2 to add
IPrefetchPathElement2 subBranchPath2 = PrefetchPathMyB.PrefetchPathMyB1;
subBranchPath2.Add(MyA1Entity.PrefetchPathMyA11);
subBranchPath2.Add(MyA1Entity.PrefetchPathMyA12);
subBranchPath2.Add(MyA1Entity.PrefetchPathMyA13);

// subbranch 3 to add
IPrefetchPathElement2 subBranchPath3 = PrefetchPathMyC.PrefetchPathMyC1;
subBranchPath3.Add(MyA1Entity.PrefetchPathMyA11);
subBranchPath3.Add(MyA1Entity.PrefetchPathMyA12);
subBranchPath3.Add(MyA1Entity.PrefetchPathMyA13);

**3. You example code **


/// the branch to add
IPrefetchPathElement2 branchPath = myRootEntity.PrefetchPathMyA;
// here the subBranch, this way you can add multiples subPaths.
branchPath.Add(subBranchPath);
branchPath.Add(MyAEntity.PrefetchPathMyA2);
branchPath.Add(MyAEntity.PrefetchPathMyA3);

I need to create 2 more IPrefetchPathElement2's


IPrefetchPathElement2 branchPath2 = myRootEntity.PrefetchPathMyB;

and

IPrefetchPathElement2 branchPath3 = myRootEntity.PrefetchPathMyC;

4. How can I add branchPath2 and branchPath3 to the rootPath.



// adding the branches to the rootPath
rootPath.Add(branchPath)

Need to add
rootPath.Add(branchPath2)   
rootPath.Add(branchPath3)

Thanks for your help.

snowball

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Mar-2007 07:52:08   

// adding the branches to the rootPath rootPath.Add(branchPath)

Need to add rootPath.Add(branchPath2) rootPath.Add(branchPath3)

There is no problem in doing the above code. (Try it) Since the branshPath is to PrefetchPathMyA And branshPath2 is to PrefetchPathMyB And branshPath3 is to PrefetchPathMyC

// subbranch 2 to add IPrefetchPathElement2 subBranchPath2 = PrefetchPathMyB.PrefetchPathMyB1; subBranchPath2.Add(MyA1Entity.PrefetchPathMyA11); subBranchPath2.Add(MyA1Entity.PrefetchPathMyA12); subBranchPath2.Add(MyA1Entity.PrefetchPathMyA13);

// subbranch 3 to add IPrefetchPathElement2 subBranchPath3 = PrefetchPathMyC.PrefetchPathMyC1; subBranchPath3.Add(MyA1Entity.PrefetchPathMyA11); subBranchPath3.Add(MyA1Entity.PrefetchPathMyA12); subBranchPath3.Add(MyA1Entity.PrefetchPathMyA13);

A simple mistake in the above code -> it should be as follows:

// subbranch 2 to add
IPrefetchPathElement2 subBranchPath2 = PrefetchPathMyB.PrefetchPathMyB1;
subBranchPath2.Add(MyB1Entity.PrefetchPathWHATEVER);
...
// subbranch 3 to add
IPrefetchPathElement2 subBranchPath3 = PrefetchPathMyC.PrefetchPathMyC1;
subBranchPath3.Add(MyC1Entity.PrefetchPathWHATEVER);
...

Note the A1 -> B1 & A1 -> C1 change.