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