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 September 4th, 2008, 03:21 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 Use of property using the Lazy Load Pattern ?

Hello All..!

I have a situation where I think the Lazy Load pattern will save me some unnecessary queries. As an example, I'm trying to get a handle on how the Category property is used in the Article Class.

I see and understand its declaration in Article.cs:

Code:
private Category _category = null;
      public Category Category
      {
         get
         {
            if (_category == null)
               _category = Category.GetCategoryByID(this.CategoryID);
            return _category;
         }
      }


But I don't see how or where it's used either in a method creation or where its used in the UI.

If someone can point me to where the Category property is further used beyond the declaration, I'd really appreciate it..!

Thanks in advance,
Ronnie

 
Old September 18th, 2008, 05:19 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Ronnie,

I haven't looked at the specific example of Category in the article.cs class. However, the lazy load 'technique' works by looking at either the parent object (i.e. the ForeignKey tables) OR it looks at the child objects (i.e. objects whose ForeignKeys point to that table). As a result of this logic, looking at the forum BLL class would result in:

Forum (Has Category parent)
-> Posts (lazy loaded children)

this would mean that you could load a forum object without explicitly having to load the Category and/or the child Posts objects (i know you probably know this, but just re-iterating it for clarity). to use the category object, you would of course do so by assigning a variable to the fourm object and referencing along the lines of:

lblTitle.Text= forum.Category.Title;

or:

foreach(Post postEx in forum.Posts)
{
    // do something with each postEx object
}

as you say, there's nothing in the beerhouse article example that alludes to this, but this is the intention of those lazy load objects. likewise, all NText objects are lazy loaded (such as Body etc) and are never picked up in the '..FromReader' methods in the DAL (you'll see a null placeholder where these properties exist), instead being picked up when their property's are referenced via a dedicated method embedded in the get{} method in the BLL.

hope this helps a little...

jimi

http://www.originaltalent.com
 
Old September 22nd, 2008, 06:45 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

Quote:
quote:Originally posted by jimibt


you would of course do so by assigning a variable to the fourm object and referencing along the lines of:

lblTitle.Text= forum.Category.Title;

or:

foreach(Post postEx in forum.Posts)
{
    // do something with each postEx object
}
Jimi,

I thought this post got past by, thanks for posting !

As usual, your explanation and example put me on the right track. Now that I see it used via a reference I realize how off I was in understanding this. I thought that the property still needed to be added to a method to be used.

I tested it out using the simple Lazy initialization and it works quit well. I'm going to play with the other variations (virtual proxy, ghost, and value holder).

It seems this approach can be pretty useful, especially when the database is normalized where many of the tables are bound with ForeignKeys/CompositeKeys and you only need to access the tables with a relationship when you need it.


On a side note: Any recommendations to a good C# book? Along the same idea as this book... something like a "C# Problems - Design - Solution". Because this book has proven to be an excellent resource, the explanation of the N-Tier approach allows to create an ACTUAL website project, not just piece mealing snippets of code to create a website.


Once again, thank you,
Ronnie

 
Old September 23rd, 2008, 03:12 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Hi Ronnie,

Glad you checked back and got a pointer in the right direction ;)

I too agree that accessing data based on strongly identified relationships within the database is a nice sharp/clean way to grab discreet sets of data, all without any complex joins.

There is actually a book that i'd recommend, i bought the eBook of it (i'd recommend that you buy the hard copy as i authorised it for my laptop and therefore it's only applicable to my laptop. problem is, i tend to re-image this occassionally, so am not sure if i'll loose the authorisation if i di this -anyway 'grab a hard copy, it's the same price'!!)

http://www.wrox.com/WileyCDA/WroxTit...470147563.html

cheers again for now.

btw - are you using the latest site builder at the moment as this lazy loads the world and her friends :). i've got a topic setup on this forum at:

http://p2p.wrox.com/topic.asp?TOPIC_ID=73963

might be a worthwhile download for you now that you've embraced the 'entity style' data model.

jimi

http://www.originaltalent.com
 
Old September 24th, 2008, 02:06 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

Jimi,

I was just kidding about a "C# Problems-Designs-Solutions" book. Didn't realize there was actually one..!! Well, I just picked up the book today. Thanks for the recommendation. I'd love to work through the entire book right now as I did with the BeerHouse book, but I have to get through this project, for now I'll use it as a reference. I still have to make it SEO friendly, culture friendly for right-to-left (he-il), add Web Services, and build the graphics and theme for them.

If anyone is interested, I got this for SEO:
http://www.wrox.com/WileyCDA/WroxTit...470131470.html

And for culture... I got the Addison .NET Internationalization book (not Wrox unfortunately).


As for Flixon... Yes..!!! I grabbed it and installed it as soon as I saw it and read the revisions on the new 2.7 release. It worked really nice, but I really need to manually build this project, it's important that I really learn everything A-Z. Also, I'm mostly using SPROC's and the DAL & BLL are designed differently, where Flixon creates a file for each table. I'll still reference to the created site. Here's the lazy loaded property it created that I also created but wasn't sure how to use it (Before this post)...

private BLL.Zones.Region.ListRegion _regionsMetroID = null;
        public BLL.Zones.Region.ListRegion RegionsByMetroID
        {
            get
            {
                if (_regionsMetroID == null)
                    _regionsMetroID = BLL.Zones.Region.GetRegionsMetroID(this.MetroID);
                return _regionsMetroID;
            }
        }

So I'll definitely use the code for reference. I also ran it against my DVD Database and I've been using it for that.. Thanks..!!

Ronnie


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

Ronnie,

I'll check out that SEO book as this is something that i've only half-heartedly worked on thus far, and is potentially (for public facing sites) one of the most important aspects. again, i'd 'imagine' that the SEO stuff works to a 'formula' in many cases and therefore could probably be incorporated into the templates once i had a handle on it - thus making it easier to maintain and uniform.

I think you're right to take the 'A-Z' approach on learning this stuff. I however, don't profess to know all of this but have gone for a 70/30 split between generated code and custom logic (in the DAL/BLL), this means that i can get to the root of the problem farily quickly and (again) in a fairly standardised/orchestrated way.

let me know how it all works out in your current project.

jimi

http://www.originaltalent.com
 
Old September 24th, 2008, 06:45 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

Jimi,

Will do... I'll be in touch. Additionally, I downloaded a while back your search control and will using it as a reference for the "RoundUp Articles" & Entity modules I'm creating. Just wanted to throw it out there and say thanks for that.

FYI: Not sure if it's all that important or you might already know, but your site is throwing an error.

Take care,
Ronnie

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

Ronnie - hi again, glad the search control is of use. I guess it could be made a bit more fully featured but for what i've been doing, it's ok for now.

re my site, i should put a more meaningful welcome page up as i'm currently remodelling that site and have removed the database connectivity for now. I'll probably not manage to get round to that for a little while, but thanks for pointing it out - easy to forget that even the odd alpha site get's clicked on occassionally :)


jimi

http://www.originaltalent.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Over-using Lazy properties in GridView? kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 November 5th, 2008 01:43 AM
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
Object Factories with Lazy Loading in C# cyberjoe C# 2 December 13th, 2006 11:21 PM
DirectoryInfo.GetFiles(pattern): search pattern fo arif_1947 VS.NET 2002/2003 1 October 19th, 2004 11:59 PM





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