Recursively nested joined entries

Posts   
 
    
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 29-Sep-2010 21:22:30   

Using 2.6 Final / 2.6.9.1202 on Postgres

(Please inform me if there is better terminology to express what I'm doing. I'm minimally-self-taught on database stuff)

I have a table of results, which has an n-ary tree of results it has replaced, either due to merging two similar results or keeping a modification history of the single result. The tree is maintained via a join table with FK's to the original and the replacing results. Relevant DDL below.

In the LLBLGen designer, for ReportEntry I've mapped the relation DeletedLinkedToSelf as ReportEntry.ReportEntryId (1:n) BucketJoin.ReportEntryId. For BucketJoin, I've mapped the relation DeletedIntermediate as BucketJoin.DeletedId (m:1) ReportEntry.ReportEntryId.

My query uses a prefetch path like so:

            
IPrefetchPath2 path = new PrefetchPath2((int)EntityType.ReportEntryEntity);
path.Add(ReportEntryEntity.PrefetchPathDeletedLinkedToSelf).SubPath.Add(BucketJoinEntity.PrefetchPathDeletedIntermediate);

with a linq query.

And finally we get to my problem. A.DeletedLinkedToSelf contains B and C, and B.DeletedLinkedToSelf contains D. But A.DeletedLinkedToSelf[0].DeletedLinkedToSelf is empty. I'd thought that since B is uniquely identified by its PK that A.DeletedLinkedToSelf[0] and B would be the same object, but that does not appear to be the case.

I'm displaying these in a treeview with a recursive constructor. When I display A as my root, I see children B and C. When I display B, I see child D.

I'm hoping there's some option I can activate to help this situation, so I don't have to do an external lookup for the directly queried entities. Thanks for your help!

CREATE TABLE report_entries ( report_entry_id SERIAL PRIMARY KEY, ... );

CREATE TABLE bucket_joins ( deleted_id integer NOT NULL, report_entry_id integer NOT NULL, join_reason integer NOT NULL, PRIMARY KEY(deleted_id, report_entry_id) );

ALTER TABLE bucket_joins ADD CONSTRAINT fk_report_join FOREIGN KEY (report_entry_id) REFERENCES report_entries (report_entry_id) ON DELETE CASCADE ;

ALTER TABLE bucket_joins ADD CONSTRAINT fk_deleted_join FOREIGN KEY (deleted_id) REFERENCES report_entries (report_entry_id) ON DELETE CASCADE ;

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Sep-2010 05:58:49   

Hi there,

I really don't follow you in every detail, but as far as I understand you have some kind of A -> B -> A prefetch issue.

Please take a look at "The X -> Y -> X graph" subject on "PrefetchPaths in Depth -> Common mistakes" in this post: http://www.llblgening.com/archive/2009/10/prefetchpaths-in-depth/#commonmistakes as I think that is your issue.

David Elizondo | LLBLGen Support Team
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 30-Sep-2010 14:51:38   

My issue is definitely similar to your X->Y->X' description, though I don't seem to have the problem exactly as you describe, instead of duplicate copies of the X' I have the correct set of X' but they are incomplete, even though I have also retrieved them as part of my set of X.

I will give try adding the Context to my metadata, thanks.

tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 30-Sep-2010 20:32:20   

That did it! Thank you so much.