I have been using the selfservice template for a while now. Due to a requirement for PocketPC support I have started to use the adaptor template. Largely due to problems with SqlCE only supporting a single connection and no pooling.
I like Lazy Loading!!!!!
I have a Contact Entity which has a FK relationship with Purpose, Location and Type entities. Each of the entities also have some sub entities. Now with Selfservice I just traversed the entities collection and it gave me the entities filled in. With adaptor this is not the case.
Could I request someone check that I am doing this right? Is this the way entities should be filled in. In addition is there no way of just saying fill all child entities with out so much code.
EntityCollection patients = new EntityCollection(new PatientEntityFactory());
IPrefetchPath2 ppath = new PrefetchPath2((int)EntityType.PatientEntity);
IPrefetchPathElement2 pcon = ppath.Add(PatientEntity.PrefetchPathContact);
pcon.SubPath.Add(ContactEntity.PrefetchPathLocationType);
pcon.SubPath.Add(ContactEntity.PrefetchPathPurposeType);
pcon.SubPath.Add(ContactEntity.PrefetchPathContactType);
pcon.SubPath.Add(ContactEntity.PrefetchPathUser).SubPath.Add(UserEntity.PrefetchPathMedicalStaff);
ISortExpression sorterCase = new SortExpression();
sorterCase.Add(SortClauseFactory.Create(CaseFieldIndex.CreatedDate, SortOperator.Descending));
pcon.SubPath.Add(ContactEntity.PrefetchPathCase,1, null, null, sorterCase).SubPath.Add(CaseEntity.PrefetchPathCaseType);
ISortExpression sorterCategory = new SortExpression();
sorterCategory.Add(SortClauseFactory.Create(CategoryFieldIndex.CreatedDate, SortOperator.Descending));
pcon.SubPath.Add(ContactEntity.PrefetchPathCategory,1, null, null, sorterCategory).SubPath.Add(CategoryEntity.PrefetchPathCategoryType);
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(PredicateFactory.CompareValue(PatientFieldIndex.Patient_ID, ComparisonOperator.Equal,mPatient.Patient_ID));
InstanceManager.DataAccessAdaptor.FetchEntityCollection(patients,filter,ppath);
I am using the Prefecth path to fill the entities.
For a particular patient entity I am getting all associated contacts and other child entitites. I had to create a point-less entity collection entity called patients, although I have a patient entity, mPatient, passed into the method.
Thanks.