Prefetch SubEntities from Database to fill in the Entity from Context without changing the ObjectId

Posts   
 
    
User001
User
Posts: 12
Joined: 19-Nov-2024
# Posted on: 22-Nov-2025 09:50:41   

Hi, I would like to know is this the proper way to prefetch SubEntity but set the SubEntity into the MainEntity from Context instead of new MainEntity through adding to the QueryParameters.CollectionToFetch?

Example: EntityX is a MainEntity, EntityY is a SubEntity of EntityX, EntityZ is a SubEntity of EntityY User wants to fetch EntityX with FilterCriteria (PK = 01) from Database first Then this EntityX will be added to the Context. Next time if user wants to prefetch EntityY. But, the system will add the EntityX with FilterCriteria (PK = 01) from the Context into the QueryParameters.CollectionToFetch first then add the PrefetchPath (EntityX prefetch EntityY) to the QueryParameter.PrefetchPathToUse. BUT If user wants to prefetch EntityZ that is not a subEntity of EntityX. I thought the EntityX will also help to prefetch the EntityZ and place it into EntityY which was prefetched before with the EntityX but it didnt. If want to do this, user need to put the EntityY from the Context into the QueryParameters.CollectionToFetch.

With this example, this helps the Entity from Context to prefetch new Entity will not have different ObjectId when need to prefetch Entity.

Question 1: How to maintain the same ObjectId (Entity from Context) so when prefetch, it will attach the Entities prefetched. Is there a proper way to do this?

Question 2: Why does only when fetch EntityX for the first time but prefetch with EntityY and EntityZ works?

Thanks.