Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 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 October 4th, 2006, 02:37 AM
Registered User
 
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't thank you enough for taking the time to answer my questions. But heres still one thing that I can't figure out. Example:
Code:
object1
property object2() as object2
...
object2
property object1() as object1
property object3() as object3
...
If some of the properties in an object is reference of another object how will I keep it from loading the entire object hierachy. And say that you have a m-to-m relationship like in the example above where object1 has a property of object2 and object 2 has a property of object1. If you were to get a list of object1 then wouldn't you end up with quite a large amount of object2:s?

 
Old October 5th, 2006, 03:22 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It all depends on how and where you load your data....

If you create and fill all your objects in public constructors, then yes, you'll create this chain or tree of objects. You create one object that in turn creates one or more objects that in turn create even more objects. But, if this is what you need, then why not? Why not have the User object create a collection of Roles that each have a separate RoleDescription (in the form of a NameValue object for example). You may end up with 20 or 30 different objects, but that shouldn't be a problem.

If you expect a large tree, both in terms of depth and in terms of the number of records, then you need to be careful. Let's assume you model a Programmer class that has a Projects collection that holds all the projects a developer has worked on. Each project would have a Client property (or a Clients collection) that in turn have a ContactPersons collection. This means that by loading a single Programmer, you could end up with 30 projects, an additional 37 Clients and maybe another 100 address records, totalling up to 168 objects. Again, if you need it, you may be able to get away with it, but obviously there is some sort of turning point where memory consumption and performance (loading objects, firing queries and so on) is no longer acceptable.

One solution is to create a Load method that loads the data:
Code:
Programmer myProgrammer = new Programmer();
// At this point, nothing has been loaded yet.
// But now we load data:
myPerson.Load();
As an alternative to an instance Load method, you could do the same with a static GetItem method.

To make the loading process a bit more fine-grained, you can create an overload that accepts a (custom) LoadTypes enum. For example:

myPerson.Load(LoadTypes.Trainings);

Then in Load you would only load the data for the requested part.

A final alternative is "lazy loading" which basically postpones getting the data until it's necessary. A simple example of a property could look like this:
Code:
private List<Client> clients;
public List<Client> Clients
{
  get
  {
    if (clients == null)
    {
      clients = GetClientsFromDatabase()
    }
    return clients;
  }
  set
  {
    client = value;
  }
}
Wether this works OK in a web app depends on the design. Sometimes, getting all data up front in one fell swoop (chunky calls) may give you better results that getting everything in little pieces (chatty calls). So, your mileage may vary.

Maybe it's time we make the discussion a little more concrete? Maybe you can describe the system you're designing in a bit more detail? It's easier to think about real world objects than about hypothetical object1 and object3 objects.... ;)

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old October 6th, 2006, 08:43 AM
Registered User
 
Join Date: Sep 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The solution we're doing is to upgrade an old asp website to the new ASP.NET 2.0. Upgrade might be the wrong word since we're planning a whole new application. But what we have is a quite large database both in tables and data, 30+ tables and the size of the database is over 1GB. This is the ground we will build from an create our objects from.
the core of the database is 4 to 5 tables wich represent Company, Person, Exhibitor, Project and Fair. All the other tables are connected or helps connects the main tables to each other wich means that there are connections between almost every table somehow. The main tables all have quite many columns, about 20+ each.

All this make for quite large and many objects and therefor the persormace issue is quite important. Since the database itself gets information from a few other places it's not an easy task to begin to change the database structure.

So what we want to be able to do in PL is for instance list all(or perhaps limit by a number) exhibititing companies on a certain project with company name and personname.

Tables include in this is:
Exhibitor wich has a foreign key to Company, a foreignkey to Project, and is connected to Person with a ExhibitorPerson table.
Company wich is connected to Exhibitor and Person, the fk is in the other tables.
Project wich is connected to Company and Exhibitor, fk in the other tables.
Person wich is connected to Company and to Exhibitor with ExhibitorPerson.

Then these tables connects to a whole lot of other tables and sometimes back to a table twice by som middletable.

So what I would like to do is something like this.
Code:
Dim Exhibitors as Exhibitor.GetListByProject(projid)
For each exhibitor in Exhibitors
Response.write(exhibitor.stand & " " & exhibitor.company.name & " " & exhibitor.person.name)
Next
But what I also want is to be able to filter the information on some random criterias, for instance in the listing above I would only want to get the persons that are tagged for maincontact in the ExhibitorPerson table.

Since there are values in the ExhibitorPerson table other than the exhibitor identification and Person identification do I make an object out of that table to or how will I get the information from there? and would that return in a code like this: exhibitor.exhibitorperson.person.name

A lot of things I want but since this is one of the first big projects I will build in this kind of way I have a lot of questions. And one of the questions is if it is worth all the time to figure out when there are free or cheap solution exsisting today, like Wilson O/R-mapper. But of course when you made it yourself you know the code and can keep it to the functions you really want/need. But I might need to study the subject a little bit more before taking on a big project like this so if you have any tips on books or sites that can provide me with code and information that would be nice.
 
Old October 9th, 2006, 02:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

There are many ways to do what you want; all depending on actual design, database, preferences, knowledge and so on.

Personally, I wouldn't create something like this: exhibitor.exhibitorperson.person.name

I see the additional data in the junction table as relation properties. So, Exhibitor.Persons(0).Name would give you the name of the first person in the collection.

Where you store other relational data depends on your model. If a SignedUp data makes sense on a Person object, you could store it there. Otherwise, you could have a class that inherirs from Person (Clients, for example) that has all the Person stuff, plus some "relational fields, like SignedUp or whatever you have stored in your ExhibitorPerson table.

In addition to that, you can give the Person collection (e.g. a class that inherits from something like CollectionBase) some additional behavior. Instead of the usual suspects like Items and Add, you could create methods like GetTaggedPersons (or make it a property TaggedPerson). Then you could do something like this:
Code:
Dim myExhibitors As List (Of Exhibitors) = Exhibitor.GetListByProject(projectId)
For Each myExhibitor in myExhibitors
  Dim myPersons As List (Of Persons) = myExhibitor.GetTaggedPersons(someTag)
  For Each myPerson in myPersons
    ' Do something with the person
  Next
Next
I am sure there must be many books about this subject, but I can't recommend one. Maybe others on this list have worked with books that describes these concepts and can recommend something? I'd be interested as well to see what's been written about this subject.

Also, consider using OR mappers. Although you may not know all of your code because you didn't write all of it, OR mappers can be very useful. If they generate good code, you don't even have to know how they operate internally; only how to use them.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Product code generator yogeshyl Excel VBA 1 October 3rd, 2007 10:50 AM
The best code documentation generator for .VS 2005 woojtii C# 2005 1 July 3rd, 2006 01:17 PM
XSLT code generator for C# asap XSLT 0 April 14th, 2006 03:54 PM
XML Development Environment and code generator ptesone XML 0 December 22nd, 2003 10:14 AM
Other things to try Martyn JSP Basics 0 August 29th, 2003 09:44 AM





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