error: The PrefetchPathElement you to tried to add is already added to this PrefetchPath. Parameter name: elementToAdd

Posts   
 
    
erichar11
User
Posts: 268
Joined: 08-Dec-2003
# Posted on: 12-May-2005 15:01:25   

Just upgraded to llblgenpro 2004.2. Regenerated the code, recompiled my project, updated the llblgen dlls to the new version and everything built fine. However when I try and execute the project, I get the following error. "The PrefetchPathElement you to tried to add is already added to this PrefetchPath. Parameter name: elementToAdd ".

Code I have is as follows which worked in the previous version:

 public static OrganizationPageEntity GetPrefetchOrganizationPage(int organizationPageId)
        {
            IPrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.OrganizationPageEntity);
            IPrefetchPathElement2 pageTypeNode = prefetch.Add(OrganizationPageEntity.PrefetchPathPageType);
            pageTypeNode.SubPath.Add(PageTypeEntity.PrefetchPathPageTypeModuleSetting);
            pageTypeNode.SubPath.Add(PageTypeEntity.PrefetchPathPageTypeDashboardSetting);
            prefetch.Add(pageTypeNode);

            OrganizationPageEntity organizationPage = new OrganizationPageEntity(organizationPageId);
            DataAccessAdapter adapter = new DataAccessAdapter();
            try
            {
                adapter.FetchEntity(organizationPage, prefetch);
                return organizationPage;
            }
        
            finally
            {
                adapter.CloseConnection();
            }
        }

Any possible insight into what I'm doing wrong would be appreciated. Thanks.

Stack Trace:

[ArgumentException: The PrefetchPathElement you to tried to add is already added to this PrefetchPath. Parameter name: elementToAdd] SD.LLBLGen.Pro.ORMSupportClasses.PrefetchPath2.Add(IPrefetchPathElement2 elementToAdd, Int32 maxAmountOfItemsToReturn, IPredicateExpression additionalFilter, IRelationCollection additionalFilterRelations, ISortExpression additionalSorter, IEntityFactory2 entityFactoryToUse) +467 SD.LLBLGen.Pro.ORMSupportClasses.PrefetchPath2.Add(IPrefetchPathElement2 elementToAdd) +17 Guidanceware.Application.Bll.Managers.OrganizationPageManager.GetPrefetchOrganizationPage(Int32 organizationPageId) in c:\documents and settings\eric richards\my documents\work\guidanceware\guidanceware\application\bll\managers\organizationpagemanager.cs:112 Guidanceware.Application.Bll.Managers.UserSettingsManager..ctor(Int32 appId, Int32 pageId, Int32 userId, Int32 companyId) in C:\Documents and Settings\Eric Richards\My Documents\work\Guidanceware\guidanceware\Application\bll\UserSettingsManager.cs:97 WebApp.Global.Application_BeginRequest(Object sender, EventArgs e) in C:\Documents and Settings\Eric Richards\My Documents\work\Guidanceware\guidanceware\Global.asax.cs:69 System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +60 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +8

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-May-2005 16:04:44   

remove prefetch.Add(pageTypeNode);

as the node is already added with:


IPrefetchPathElement2 pageTypeNode = prefetch.Add(OrganizationPageEntity.PrefetchPathPageType);

simple_smile . This exception shows you these common mistakes now, so the code will work as expected. You didn't notice it but you fetched teh graph twice.

Frans Bouma | Lead developer LLBLGen Pro
erichar11
User
Posts: 268
Joined: 08-Dec-2003
# Posted on: 12-May-2005 17:14:05   

Thanks, that worked. But I'm a little confused as it worked in the previous version. I'm assuming there is some change between the way prefetch worked in the previous version vs 2004.2. The reason I ask is I have other prefetch paths and just want to be sure I understand whats happening.

Or.., am I missing something flushed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-May-2005 18:18:10   

The check was added to 1.0.2004.2. So in previous versions teh addition was done, and no check/exception was thrown. You didn't notice this, as you added the tree twice, so the second time data was fetched, and not merged with the right objects.

Frans Bouma | Lead developer LLBLGen Pro