Otis wrote:
How is 'User' defined as a class? A derived class from UserEntity?
public sealed class User : BusinessEntity2ABC, IEntity2, IBusinessEntity, IPerson
It is a wrapper around UserEntity and it implements IEntity2 (and IEntityCore, etc.). For each interface method, it simply calls the UserEntity method/property.
Otis wrote:
do you setup prefetch paths somewhere to fetch the related person entity? (this is a bit unclear from your posting)
Yes. We have experimented with this a lot. Of course, the prefetch paths work fine when we use a UserEntityFactory, but not with a UserFactory. Here's some simplified code:
public static User GetUser(...)
{
IPredicateExpression filterExpression = new PredicateExpression();
filterExpression.Add(
PredicateFactory.CompareValue(UserFieldIndex.ID, ComparisonOperator.Equal, ID));
filterExpression.AddWithAnd(...);
EntityCollection items = GetFilteredUsers(filterExpression);
...
}
private static EntityCollection GetFilteredUsers(IPredicateExpression filterExpression)
{
EntityCollection users = new EntityCollection(new UserFactory());
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.Relations.Add(UserEntity.Relations.PersonEntityUsingPersonID);
filterExpression.Add(
PredicateFactory.CompareValue(UserFieldIndex.Deleted, ComparisonOperator.Equal, "false"));
filter.PredicateExpression.Add(filterExpression);
IPrefetchPath2 prefetchPerson = new PrefetchPath2((int)EntityType.UserEntity);
prefetchPerson.Add(UserEntity.PrefetchPathPerson, new PersonFactory());
ISortExpression sorter = new SortExpression(
SortClauseFactory.Create(UserFieldIndex.ID, SortOperator.Ascending));
DataAccessAdapter adapter = new DataAccessAdapter();
try
{
adapter.FetchEntityCollection(users, filter, 0, sorter, prefetchPerson);
}
I'm trying to figure out if the problem is related to the fact that we use the Wrapper pattern rather than inheritance for the User class, or whether we are just missing something (such as adding Relations to the filter). Looking at the code, I see the proper relations already exist in the generated code and I feel like the Wrapper design should not interfere with proper utilization of this code:
public static IPrefetchPathElement2 PrefetchPathPerson
{
get
{
return new PrefetchPathElement2(
new EntityCollection(new PersonEntityFactory()),
UserEntity.Relations.PersonEntityUsingPersonID,
(int)EntityType.UserEntity, (int)EntityType.PersonEntity, 0, null, null, null, null, "Person", RelationType.ManyToOne);
}
}