Hello
I am pulling my hair out as I have no idea what I am doing wrong, I'm sure it must be obvious.. and I have read through the other threads..!
I am using adapter with LLBL version 2.6.
I am trying to call back an entity with a few prefectches and sort on a column in one of the prefetched tables!
The tables are:
ProductControl
ProductControlControlItem
ProductControlItem
ProductControl is my entity, ProductControls contain ProductControlItems, and these are linked using the productcontrolcontrolitem.
ProductControlControlItem has 3 columns, ProductControlID, ProductControlItemID and order.
I want to call back A ProductControl with all its controlItems ordered by Order.
To me this sound simple enough.. but the ordering isn't working.
My first version of the code is here:
public static ProductControlEntity GetControlWithItems(Guid controlId)
{
ProductControlEntity control = new ProductControlEntity(controlId);
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.ProductControlEntity);
SortExpression sorter = new SortExpression(ProductControlControlItemFields.Order | SortOperator.Ascending);
IRelationCollection relation = new RelationCollection(ProductControlItemEntity.Relations.ProductControlControlItemEntityUsingControlItemId);
prefetchPath.Add(ProductControlEntity.PrefetchPathProductControlItemCollectionViaProductControlControlItem, 0, null, relation, sorter);
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntity(control, prefetchPath);
}
return control;
}
This brings back everything but not in the right order.
I figured I must use a subpath or some sort.. here is one version I have tried (I've tried a few) and this just causes an error:
public static ProductControlEntity GetControlWithItems(Guid controlId)
{
ProductControlEntity control = new ProductControlEntity(controlId);
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.ProductControlEntity);
SortExpression sorter = new SortExpression(ProductControlControlItemFields.Order | SortOperator.Ascending);
IRelationCollection relation = new RelationCollection(ProductControlEntity.Relations.ProductControlControlItemEntityUsingControlId);
IRelationCollection relation2 = new RelationCollection(ProductControlControlItemEntity.Relations.ProductControlItemEntityUsingControlItemId);
prefetchPath.Add(ProductControlEntity.PrefetchPathProductControlControlItem, 0, null, relation, sorter).SubPath.Add(ProductControlEntity.PrefetchPathProductControlItemCollectionViaProductControlControlItem, 0, null, relation2);
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntity(control, prefetchPath);
}
return control;
}
I have tried other sub paths, as I am sure this must be the way to do it, but am getting either errors or nulls for some of the prefetches!
Please help!!
Bex