We were using "lazy loading" to hook tables together and hop from one to the other. This raised a performance issue, and after researching am trying to switch the code to use prefetch path's, then loop through the GetMulti, and map to a custom class. I believe I have the prefetch working. How do I get the additional entities retrieved out of the base entity?
The following code is my fetch...
List<TMSUser> lstTMSUsers = new List<TMSUser>();
_tmsUserCollection = new TmsUsersCollection();
// filter statement
IPredicateExpression filter = new PredicateExpression();
// sort statement
ISortExpression sortBy = new SortExpression(EnterpriseUserFields.LastName | SortOperator.Ascending);
sortBy.Add(EnterpriseUserFields.FirstName | SortOperator.Ascending);
IRelationCollection relations = new RelationCollection();
relations.Add(TmsUsersEntity.Relations.EnterpriseUserEntityUsingUserId);
IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.TmsUsersEntity);
prefetchPath.Add(TmsUsersEntity.PrefetchPathEnterpriseUser);
prefetchPath.Add(TmsUsersEntity.PrefetchPathDivisions);
prefetchPath.Add(TmsUsersEntity.PrefetchPathSamOrgs);
_tmsUserCollection.GetMulti(filter, 0, sortBy, relations, prefetchPath);
if (_tmsUserCollection != null)
{
if (_tmsUserCollection.Items.Count > 0)
{
foreach (TmsUsersEntity e in _tmsUserCollection)
{
lstTMSUsers.Add(new TMSUser(e, _authenticatedUser));
}
_tmsUserCollection.Clear();
}
}
TMSUser is a custom class that we use to pass back to our UI. The code above is a snippet from our ServiceFacade, and makes it easy for the UI developers, as they do not have to write any DAL code :-).
In my TMSUser class, I was using the following to map fields using "lazy loading".
_projectCodeType = _tmsUserEntity.Divisions.ProjectCodeType;
_lastName = _tmsUserEntity.EnterpriseUser.LastName;
_firstName = _tmsUserEntity.EnterpriseUser.FirstName;
_email = _tmsUserEntity.EnterpriseUser.UserEmail;
_loginName = _tmsUserEntity.EnterpriseUser.LoginName;
_divisionName = _tmsUserEntity.Divisions.DivisionName;
_canManageOwnProjects = _tmsUserEntity.Divisions.CanManageOwnProjects;
_divisionAgencyCode = _tmsUserEntity.Divisions.AgencyCode;
This turned out to be a performance issue, as we are creating a List of Users to return, hence the research in prefetch paths.
How do I accomplish the same thing with prefetch paths? I know this is a silly question, but cannot find any examples in the help files or forum. Maybe I am searching on the wrong thing? Any help you could provide would be greatly appreciated. We are using SQLServer 2005, VS 2005, C#, SelfServicing-TwoClasses.
Thanks, Cory