Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 3rd, 2008, 09:26 PM
Authorized User
 
Join Date: Mar 2008
Posts: 62
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via Yahoo to kalel_4444
Default Over-using Lazy properties in GridView?

Hello All,

My question is, when using multiple lazy-loaded properties in a GridView, is there a call to the database for each property ?

Here's my situation:

I have just completed a ProfileListing.ascx control, following the desgin of the ArticleListing control in TBH (except for creating a custom pager & sorter to make it SEO friendly, it's pretty much the same) and it seems to load quickly locally. In my gridview list, each row contains data from 2 tables (Profiles & Addresses). So:

Profiles.AddressID(FK) ---> Addresses.AddressID(PK)

Lazy Initialization:
      
Code:
private Address _addressParentDetails = null;
Code:
      public Address AddressParentDetails
      {
         get
         {
            if (_addressParentDetails == null && this.AddressID != 0)
               _addressParentDetails = Address.GetAddressByID((int)this.AddressID);
            return _addressParentDetails;
         }
      }


In each Gridview row, I'm accessing both data from an ObjectDataSource in BLL.Profiles.GetProfiles and various Lazy Loaded properties using the above initialization like so:

<ItemTemplate>
<%# Eval("AddressParentDetails.Phone") %>
<%# Eval("AddressParentDetails.Address1") %>
<%# Eval("AddressParentDetails.Address2") %>
<%# Eval("AddressParentDetails.Address3") %>
<%# Eval("AddressParentDetails.City") %>
<%# Eval("AddressParentDetails.State") %>
<%# Eval("AddressParentDetails.PostalCode") %>
<%# Eval("AddressParentDetails.Country") %>
<ItemTemplate>

So again, in the above example, am I accessing AddressParentDetails 8 times or once ? If so, alternatively would it be better just to nest another ObjectDataSource (BLL.Addresses.GetAddressByID), grab the entire Address collection, but at least grab it only once ?

Any insight is appreciated..! :)

Thank you,
Ronnie

 
Old November 4th, 2008, 06:54 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Hi Ronnie,

You're only accessing the AddressParentDetails (or should i say, _addressParentDetails) once for each row as the variable is set on the 1st invocation and then just acesses it's properties thereafter. Not only that, if you are using cacheing on the BLL (which i presume you are), you will only ever hit the database on cache expiry for the address object of that address_id or when it's been amended. so, in effect, you could only hit the database a few times a day for that address_id all going well. the real benefit of course being that you'd only ever load it in the 1st place if you explicitly requested it, otherwise, your 'list' would skip over it without actually requesting data from it.

a win/win situation...

jimi

http://www.originaltalent.com
 
Old November 5th, 2008, 01:43 AM
Authorized User
 
Join Date: Mar 2008
Posts: 62
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via Yahoo to kalel_4444
Default

Hi Jimi,

Thanks for the response and confirmation on this, I was a bit uneasy and not sure about this.

I'm now creating another similar control, but with a ListView and the DataPager and I'll still be using the Lazy-loaded properties with this and throughout the project.

Thanks again..!! :)
Ronnie






Similar Threads
Thread Thread Starter Forum Replies Last Post
Lazy Load... Cool but... pbernardo01 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 December 28th, 2007 02:00 AM
Is the Internet making programmers lazy? dparsons Intro Programming 12 April 8th, 2007 10:45 AM
Object Factories with Lazy Loading in C# cyberjoe C# 2 December 13th, 2006 11:21 PM
Adding Properties to Buttons in a GridView Aaron Edwards ASP.NET 2.0 Basics 3 July 23rd, 2006 01:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.