Records that have self referential foreign keys don't fill prefetches (likely expected behavior).

Posts   
 
    
JohnL
User
Posts: 47
Joined: 07-Oct-2005
# Posted on: 05-May-2022 23:22:46   

In our database with have a table: PolicyProspect, which has the primary key PolicyProspectGuid and also has a nullable foreign key RenewalOfPolicyProspectGuid.

When we get a new policy, the renewal is left null, but when a policy is renewed, the link from the new policy to the old is documented via that foreign key. This has never caused any issues until we tried to create a report that uses the structure:

    //These would be policies that were potentially renewed
    EntityCollection<PolicyProspectEntity> policies = new EntityCollection<ORM.EntityClasses.PolicyProspectEntity>();
    
    //Starting from our new policies...
    PrefetchPath2 path = new PrefetchPath2(EntityType.PolicyProspectEntity);
    //get the policies they were renewed from (these are also PolicyProspectEntities)
    var oldPolicy = path.Add(PolicyProspectEntity.PrefetchPathRenewalOfPolicyProspect).SubPath;
    //And then get the carrier submission.
    var oldSubmissions = oldPolicy.Add(PolicyProspectEntity.PrefetchPathCarrierSubmission).SubPath;
    
    QueryParameters param = new QueryParameters();
    param.PrefetchPathToUse = path;
    param.CollectionToFetch = policies;
    
    DataAccessAdapter adapter = new DataAccessAdapter();
    await adapter.FetchEntityCollectionAsync(param, CancellationToken.None);

The expected behavior would be for the items in the RenewalOfPolicyProspect collection to have their CarrierSubmission data prefetched. However, this doesn't happen when a policy is both in the base data set and in the child data set. My guess is that as the entity is already loaded during the execution of the base, the existing record is reused in the Renewal set and thus does not execute the prefetch path (which is only specified for the child data set).

We have worked around this via a view (and this is from a huge database has been using LLBLGen since version 2, so this isn't an issue that comes up often), so this is more curiosity as to what the best approach to queries that would expect to see the same record in multiple places in the prefetch graph.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 06-May-2022 09:36:30   

Which version of LLBLGen Pro are you using?

What's the type of relation between Policy and Carrier Submission?

JohnL
User
Posts: 47
Joined: 07-Oct-2005
# Posted on: 06-May-2022 18:03:36   

Walaa wrote:

Which version of LLBLGen Pro are you using?

What's the type of relation between Policy and Carrier Submission?

Sorry, had the technical details in and then trimmed a bunch of the content for length. This is 5.9.1 and is reproduced both using the Standard 2.0 library and the Framework library (under 4.8 ).

The CarrierSubmission.PolicyProspectGuid is a foreign key to PolicyProspect as a many to one relationship. However, that doesn't matter, I can use any relationship off of PolicyProspect and reproduce this (they will load for all of the records that are uniquely in the child collection, but fail to load if the record appears in the base collection and the child collection.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-May-2022 09:13:34   

It's unclear to me what you mean with "base collection and the child collection". Plus, I don't reall understand the relationships, as the second subpath RenewalOfPolicyProspect is apparently also of type PolicyProspect as you add a prefetch path node to the second subpath of a node related to PolicyProspect.

So either please attach the project or describe in simple terms what the relationships are (e.g. PolicyProspect.RenewalOfPolicyProspect m:1 PolicyProspect.Renewals)

Frans Bouma | Lead developer LLBLGen Pro