No- the problem is that there is a static set of fields that i need to display. However, i also need to sort and/or filter on each field in that set, depending on user input. I'm not adding the relations dynamically, I just add them all:
//add Relations for all filterable/sortable fields
IRelationPredicateBucket bucket = new RelationPredicateBucket(SubassemblyFields.AssemblyNum % filterVal);
bucket.Relations.Add(SubassemblyEntity.Relations.C_StatusEntityUsingStatusId);
bucket.Relations.Add(SubassemblyEntity.Relations.C_SubassemblyTypeEntityUsingSubassemblyTypeId);
bucket.Relations.Add(SubassemblyEntity.Relations.FMUserAccountEntityUsingCreatedByUserAccountId, Constants.ALIAS_USER_CREATEDBY);
bucket.Relations.Add(SubassemblyEntity.Relations.FMUserAccountEntityUsingModifiedByUserAccountId, Constants.ALIAS_USER_MODIFIEDBY);
bucket.Relations.Add(SubassemblyEntity.Relations.C_LockStatusEntityUsingLockStatusId);
bucket.Relations.Add(SubassemblyEntity.Relations.FMUserAccountEntityUsingLockedByUserAccountid, Constants.ALIAS_USER_LOCKEDBY, JoinHint.Left);
there is other code that builds up the Predicates and SortExpression. That works fine, because all the sortable/filterable fields are included in the above set of relations.
The problem comes when I want to project my resultset (an EntityCollection<SubassemblyEntity> in this case) into another form, for displaying in a grid-type control. Even though each of the tables I need has been JOINed into the query, I still have to add a matching set of Prefetches in order to actually access the related Entities. For example, to display the field C_LockStatus.Code in my search results. So, in order to access the related entities, I have to add this:
IPrefetchPath2 pf = new PrefetchPath2(EntityType.SubassemblyEntity);
//need to display C_LockStatus.Code in results view
pf.Add(SubassemblyEntity.PrefetchPathC_LockStatus);
//need to display C_SubassemblyType.Code in results view
pf.Add(SubassemblyEntity.PrefetchPathC_SubassemblyType);
//need to display Lock UserAccount.DisplayName in results view
pf.Add(SubassemblyEntity.PrefetchPathLockedByFMUserAccount);
//need to display Modified UserAccount.DisplayName in results view
pf.Add(SubassemblyEntity.PrefetchPathModifiedByFMUserAccount);
//need to display C_Status.Code in results view
pf.Add(SubassemblyEntity.PrefetchPathC_Status);
Then it all works. However, it ends up generating 6 queries instead of 1. Which I would expect, since I'm having to use the Prefetches.
My question is- since the related entities are already being included in the 'main' query (using those Relations), is there some way to access them without adding the per-related-entity Prefetches? It's basically fetching the same data multiple times in this scenario.
Thanks.