Refetch with prefetch into same entity after save

Posts   
 
    
Kirk
User
Posts: 22
Joined: 26-Apr-2004
# Posted on: 10-May-2006 01:10:14   

I seem to be having a problem with the following


void SaveSubCase(SubCaseEntity subCase)
{
da = new DataAccessAdapter(Connection.PTCDB, true);
da.SaveEntity(subCase, false);

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.SubCaseEntity);
IPrefetchPathElement2 subCaseDetailNode = prefetchPath.Add(SubCaseEntity.PrefetchPathSubCaseDetail);  
IPrefetchPathElement2 caseDetails = subCaseDetailNode.SubPath.Add(SubCaseDetailEntity.PrefetchPathCaseDetails);
caseDetails.SubPath.Add(CaseDetailsEntity.PrefetchPathPeople);

//SubCaseEntity sc = new SubCaseEntity(subCase.Id)
da.FetchEntity(subCase, prefetchPath);
}

When I execute this I do not get the CaseDetailsEntity prefetched as expected. SQL Profiler shows the proper SQL statements being executed. If I uncomment sc and da.FetchEntity(sc, prefetchPath) all prefetches are done as expected. Is there something wrong with the code sequence above?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-May-2006 09:06:55   

SQL Profiler shows the proper SQL statements being executed

Try to run those statements against the database to see if they return valid results.

Kirk
User
Posts: 22
Joined: 26-Apr-2004
# Posted on: 10-May-2006 14:52:40   

I did run the SQL statements and they did produce the proper results. Those results did not appear to be reflected in the entities when the subCase entity was re-used, but were reflected in the entities when a new SubCaseEntity was created and used.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 10-May-2006 15:25:28   

Use a context to refetch using a prefetch path in existing entities. So add the root, existing entities to the context, then fetch the entities again with the prefetch path.

Frans Bouma | Lead developer LLBLGen Pro