Geeks With Blogs
Server Error in Application An unhandled exception occurred during the execution of the current web request

Not to load code modules into memory until you are sure you are going to be required. Example:

I am having Category and Sub-Category. Category can hold list of Sub-Category, but this sub-category is not require every time. I’ll load sub-category when it is required. I am using following code to achieve this.


public class Category



      // Other Geter Seter..


      private List<SubCategory> _subCategories;

   /// <summary>

        /// Sub Categories

        /// </summary>

        public List<SubCategory> SubCategories




                //Lazy Load

                if (_subCategories == null)

                    _subCategories = GetSubCategories(this.ID);

                return _subCategories;


            set { _subCategories = value; }




I’ll not fill list of sub-category in default load of Category object (cunstructor or some Load method) instant of I’ll load list of sub-category when it is acthuly required.

ASP.NET Interview Questions | C# Interview Questions | .NET Interview Questions | Dot Net Interview Questions | VB.NET Interview Questions | Oracle Interview Questions Posted on Thursday, October 26, 2006 9:42 AM C# , Design Pattern | Back to top

Comments on this post: Lazy Loading

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Mahesh Singh | Powered by: