Making a mistake with "Polymorphic Prefetch Paths"

Posts   
 
    
bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 02-Aug-2006 23:19:57   

Hello

I have a question about “Polymorphic Prefetch Paths,” I am using adapter setup, and I have read the little entry on the manual about this.

Here is my database lay out

PointIndex -> (key)PointType -> (key)Protocol -> (key)ProtocolSettingGroupInfo.

I am trying from a record from PointIndex to read a text entry related to that record on ProtocolSettingGroupInfo.

I am using the following code:


EntityCollection pointIndexCollection = new EntityCollection(new PointIndexEntityFactory());

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.PointIndexEntity);
prefetchPath.Add(ProtocolEntity.PrefetchPathProtocolSettingGroupInfo);


RelationPredicateBucket bucket = new RelationPredicateBucket();

IPredicateExpression filter = new PredicateExpression();
filter.Add(PredicateFactory.CompareValue(PointIndexFieldIndex.PointIndexID,ComparisonOperator.Equal,0));

bucket.PredicateExpression.Add(filter);

int returnRecords = 0;

using (DataAccessAdapter dataAccessAdapter = new DataAccessAdapter(ConnectionString.GetZoneServer()))
{
    try
    {
        dataAccessAdapter.FetchEntityCollection(pointIndexCollection, bucket, prefetchPath);
        returnRecords = pointIndexCollection.Count;
    }
    catch(Exception e)
    {
        Console.WriteLine(e.ToString());
    }
}

And I get the following error when trying to run it: System.ApplicationException: The prefetch path element at index 0 in the passed in prefetch path for root entity type 12 is meant for root entity type 23 which isn't a subtype of 12 at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchParameterisedPrefetchPath(IEntityCollection2 rootEntities, Int64 maxNumberOfItemsToReturn, IPrefetchPath2 prefetchPath) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchPrefetchPath(IEntityCollection2 rootEntities, IRelationPredicateBucket filterBucket, Int64 max NumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, IPrefetchPath2 prefetchPath) at InformationIntellect.DVM.ZoneServer.CO.Debug.TerminalTest.Main(String[] args) in C:\InformationIntellect\DVM\ZoneServer\CO.Debug\TerminalTest.cs:line 52

Could someone please point me in the right direction?

Thank you, BrunoV

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Aug-2006 06:55:49   

You should start the prefetchPath from the entity you are fetching and move along the chain using SubPaths till you reach your final entity.

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.PointIndexEntity);
prefetchPath.Add(PointIndexEntity.PrefetchPathPointType).SubPath.Add( PointTypeEntity.PrefetchPathProtocol).SubPath.Add(ProtocolEntity.PrefetchPathProtocolSettingGroupInfo);

bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 03-Aug-2006 14:52:11   

It worked

Thank you very much Walaa.

I knew I was just missing a piece of fundamental information.