System.InvalidOperationException

Posts   
 
    
oskarf
User
Posts: 19
Joined: 05-May-2023
# Posted on: 05-May-2023 15:51:56   

LLBLGen.Pro versions are 5.5.2

Message=The prefetch path element at index 0 in the passed in prefetch path for root entity type 508 is meant for root entity type 507 which isn't a subtype of 508. This means that you've added a prefetch path node to a Path of an unrelated entity, for example adding OrderDetailsEntity.PrefetchPathProduct to a prefetch path for CustomerEntity.

I've a prefetch object with RootEntityType = 508 that contains two child enities with the property DestinationEntityType = 507.

Does these numbers have to be the same? Wondering what to make of this error.

Details:

System.InvalidOperationException
  HResult=0x80131509
  Message=The prefetch path element at index 0 in the passed in prefetch path for root entity type 508 is meant for root entity type 507 which isn't a subtype of 508. This means that you've added a prefetch path node to a Path of an unrelated entity, for example adding OrderDetailsEntity.PrefetchPathProduct to a prefetch path for CustomerEntity.
  Source=SD.LLBLGen.Pro.ORMSupportClasses
  StackTrace:
   at SD.LLBLGen.Pro.ORMSupportClasses.PrefetchPathFetcher.ProducePathNodeParameters(QueryParameters rootNodeParameters, Int32 nodeIndex, Int32 parameterisedPrefetchPathThreshold, ITransaction transactionToUse)
   at SD.LLBLGen.Pro.ORMSupportClasses.PrefetchPathFetcher.FetchPrefetchPath(QueryParameters rootNodeParameters, Boolean forceParameterizedPPath, ITransaction transactionToUse, Int32 parameterisedPrefetchPathThreshold, Action`1 fetchNodeFunc, Action`4 mergeManyToManyFunc)
   at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceCore.FetchPrefetchPath(QueryParameters rootNodeParameters, Boolean forceParameterizedPPath, ITransaction transactionToUse, Int32 parameterisedPrefetchPathThreshold, Action`1 fetchNodeFunc, Action`4 mergeManyToManyFunc)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.<>c__DisplayClass13_0.<FetchPrefetchPath>b__0()
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.FetchAdditionalPrefetchPath(IPrefetchPath2 prefetchPath, Context contextToUse, IEntity2 fetchedEntity, IRelationPredicateBucket filterToUse)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.FetchEntityUsingFilter(IEntity2 entityToFetch, IPrefetchPath2 prefetchPath, Context contextToUse, IRelationPredicateBucket filter, ExcludeIncludeFieldsList excludedIncludedFields)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.FetchEntity(IEntity2 entityToFetch, IPrefetchPath2 prefetchPath, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.<>c__DisplayClass9_0.<FetchEntity>b__0()
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.FetchEntity(IEntity2 entityToFetch, IPrefetchPath2 prefetchPath)
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 05-May-2023 17:40:45   

It might help if you give the prefetch path code you wrote.

Basically, if you define a prefetch path for entity X and you add a prefetch path edge for entity Y. See the below example:

using(DataAccessAdapter adapter = new DataAccessAdapter())
{
    OrderEntity o = new OrderEntity(10254);
    var p = new PrefetchPath2(EntityType.OrderEntity);
    p.Add(CustomerEntity.PrefetchPathEmployees);
    Assert.IsTrue(adapter.FetchEntity(o, p));
}

This throws the same exception, because the prefetch path element added (CustomerEntity.PrefetchPathEmployees) is Customer - Employee, but the prefetch path root is Order, not Customer. The root is the entity you're fetching, the elements added to the path are edges in a graph starting from that root. So here I have 'order' so I have to first add a prefetch path element from Order, e.g. OrderEntity.PrefetchPathCustomer. This will fetch the related customer entity or entities for the root entity 'order'. See https://www.llblgen.com/Documentation/5.10/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Adapter/gencode_prefetchpaths_adapter.htm

Frans Bouma | Lead developer LLBLGen Pro
oskarf
User
Posts: 19
Joined: 05-May-2023
# Posted on: 05-May-2023 18:36:07   

The code is

var measurementEntity = new PcMeasurementsEntity(measurementId);
            var prefetch = new PrefetchPath2(EntityType.PcMeasurementsEntity)
             {
                PcMeasurementsEntity.PrefetchPathPcMeasurementsItems,
                {
                    PcMeasurementsEntity.PrefetchPathGpatient, new IncludeFieldsList(GPatientFields.Dob, GPatientFields.Sex)
                }
             };
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 06-May-2023 09:10:46   

I can't reproduce it:

[Test]
public void PkFetchTestWithPrefetchPath()
{
    using(DataAccessAdapter adapter = new DataAccessAdapter())
    {
        OrderEntity o = new OrderEntity(10254);
        var p = new PrefetchPath2(EntityType.OrderEntity)
                {
                    OrderEntity.PrefetchPathOrderDetails,
                    {
                        OrderEntity.PrefetchPathCustomers, new IncludeFieldsList(CustomerFields.CompanyName)
                    }
                };
        Assert.IsTrue(adapter.FetchEntity(o, p));
        Assert.IsNotNull(o.Customers);
    }
}

Works fine (5.10). 5.5.2 is rather old, tho this code is in the runtime for a long time so I doubt there was an issue in this area.

Please give us more information or a repro case as we can't see what's wrong with just a few lines of code: is there more added to the path later? So show a minimal code snippet that reproduces the problem

Frans Bouma | Lead developer LLBLGen Pro
oskarf
User
Posts: 19
Joined: 05-May-2023
# Posted on: 09-May-2023 12:38:01   

I think this error must be related to the data itself rather than the actual code. I'll leave this issue for now as this code normally works.