Hi, I think this is easy to solve, but I cannot get it to work.
I have 3 tables (entities) which are related
A , B, C
A is related to B
B is related to C
I want to retrieve all B entities filtered on a value in the A entity. Every B entity has also a value in C, which should also be retrieved. Actually all records form B and the related (1:1) records from C
I use the following code where A = anamnesis, B= IbpAnamnesisInputEntity and C = IbpAnamnesisItem:
IbpAnamnesisEntity anamnesis = LoadAnamnesis(clientId);
EntityCollection<IbpAnamnesisInputEntity> myCollection =
new EntityCollection<IbpAnamnesisInputEntity>(new IbpAnamnesisInputEntityFactory());
PrefetchPath2 path = new PrefetchPath2((int)EntityType.IbpAnamnesisInputEntity);
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(IbpAnamnesisInputFields.IbpanamnesisId == anamnesis.IbpanamnesisId);
//IRelationPredicateBucket RelationAnamnesisItem = new RelationPredicateBucket();
//RelationAnamnesisItem.PredicateExpression.Add(IbpAnamnesisInputFields.IbpanamnesisItemId == anamnesis.IbpanamnesisId);
ISortExpression sort = new SortExpression(IbpAnamnesisItemFields.OrderId | SortOperator.Ascending);
path.Add(IbpAnamnesisInputEntity.PrefetchPathIbpAnamnesisItem, 0, null, null, sort);
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(myCollection, filter,path);
}
return myCollection;
The problem is I want to show the collection sorted on the orderId in IbpAnamnesisItem-table but I cannot get it to work. If I take a look at the generated query the related Table (IbpAnamnesisItem) is not available. Only the fields in the IbpAnamnesisInput are in the query.
How can I solve this?