none
Performance question RRS feed

  • Question

  • I have 3 classes: School,  Student, Award.  And the method is to get the Awards of the Students of the School.  It become extremely slow.  Can somebody tell me why?  And How can I make it faster?  Thanks!  All reply will be appreciated!

    School.GetAwards():

    ---------------------------------------------------------------

    public List<Awards> GetAwards()
    {
                List<Listing> returnListing = new List<Awards>();
                List<Student> sList = Students.Where(s => s.Awards.Count > 0).ToList();
                foreach (Student s in sList)
                {
                    returnListing.AddRange(s.GetAwards());
                }
                return returnListing;
    }

    -----------------------------------------------------------------

    The method s.GetAwards looks like:

    ----------------------------------------------------------------

     public List<Award> GetAwards()
            {
                List<Award> aList;
                aList = Listings.Where(l => l.StatusTypeId == aStatusType.ActiveId).ToList();
                aList.AddRange(Listings.Where(l=>l.StatusTypeId == aStatusType.ArchevedId));
                aList.AddRange(Listings.Where(l=>l.StatusTypeId==aStatusType.CancelId));
                aList.AddRange(Listings.Where(l=>l.StatusTypeId==aStatusType.UnderConsiderationId));
                return aList;
            }
    ---------------------------------------------------------------------------

     

     

     

     

    Wednesday, April 14, 2010 8:38 PM

All replies

  • It can be caused by different things, have you tried to debug print the Sql out and execute it manually?

    Besides that, it looks like you are executing : .Where(l => l.StatusTypeId == aStatusType.ActiveId).ToList();  and that could be a potential killer depending on how many Students there is in the sList.

    Furthermore I don't see the point in calling GetAwards for each, it looks to me as it returns the same each time.

     

     

     

    Thursday, April 15, 2010 8:48 AM