PrefetchPath SelfServicing questions

Posts   
 
    
Posts: 14
Joined: 07-Dec-2006
# Posted on: 14-Apr-2007 16:29:07   

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

Posts: 254
Joined: 16-Nov-2006
# Posted on: 14-Apr-2007 21:48:46   

Hi Cory,

How do I get the additional entities retrieved out of the base entity?

What do you mean base entity, are you using an entity hierarchy, if so can you specify what it is?

I'm confused as to your query regarding prefetch paths, which part is not working for you here?

Posts: 14
Joined: 07-Dec-2006
# Posted on: 15-Apr-2007 03:51:26   

Hi Matt,

I was having trouble finding the right words to describe my problem. I found my answer through trial and error today. If you look at the initial thread, the following is what I was looking for...

SamOrgsEntity samOrgs = new SamOrgsEntity(); samOrgs = _tmsUserEntity.GetSingleSamOrgs(); DivisionsEntity division = new DivisionsEntity(); division = _tmsUserEntity.GetSingleDivisions(); EnterpriseUserEntity enterpriseUser = new EnterpriseUserEntity(); enterpriseUser = _tmsUserEntity.GetSingleEnterpriseUser();

Then I can set properties of our custom classes...problem fixed. Thanks!