Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 22nd, 2006, 08:21 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code generator and some other things

Were there any codegenerator used to generate the classes in this book and in that case wich one?
Can you consider the DAL in the examples in this book to be a light version of an O/R-mapper?
Is the examples given in this book any good applying on more advanced databases and applications or is it simple code for simple functions?
  #2 (permalink)  
Old September 23rd, 2006, 05:21 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Hyzac,

I used Visual Studio's Class Designer to generate most of the objects, properties and methods for the applications in my chapters.

I also used a small in-house code generator to generate parts of the data access layer code.

I don't think the concepts used in my book can be see as an O/R mapper. One of the characteristics of an O/R mapper is that code is generated automatically; it's also quite often updateable, either through regeneration of code, or dynamically at run-time.

I have used the code from the book in many applications, from very small to very large. So, it certainly works in larger real-world applications.

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.
  #3 (permalink)  
Old September 25th, 2006, 01:22 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the answers and thanks for an excellent book.

  #4 (permalink)  
Old September 25th, 2006, 01:25 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You're more than welcome....

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.
  #5 (permalink)  
Old September 28th, 2006, 07:13 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have some followup questions on the subject wich might be a little bit out of the scope of the book.
Regarding relationships:

Wich is the easiest way to handle relationship with the code that are used in the book? It seems that if you want to make a list of Contents in the CMS example and put it in a gridview you have to bind the content type column to its own datasource to get the text instead of the id.
I've read http://msdn.microsoft.com/library/de...CustEntCls.asp this article and here they manage relationships by setting the property contenttypeid as a contenttype object if I were to use the database in the CMS example.

Does that mean that it would be enough with one datasource on a page to get all the information on an object? But it feels like this could produce some overhead since I might not need all the data in property-object. To solve this I've heard something called lazyloading but I can't find any good examples how to fix that functionality.

As I said, this might very well fall out of the scope of the book but it would be nice to get some professional opinion on the subject since I'm quite new to the oo-architecture.
  #6 (permalink)  
Old September 29th, 2006, 08:51 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To make the previous post a little bit simpler: How do I print a list with all the contents in the Contenttable in a gridview wich still shows the contentype text in the column. In the book the contents is filtered by a dropdownlist and thus you can get the information from there.

To put it in a more extreme situation say I have a table that has a lot of foreign keys say 5. How do I solve that in a good performance way? Do I have to put 5 different objectdatasources on the page and called the Get function on every RowDataBound to get that items text or is there som easier way?

  #7 (permalink)  
Old September 30th, 2006, 08:46 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Hyzac,

Performance and design are indeed interesting issues that need to be dealt with here. In an SqlDataSource, things are simple. You just change the SQL statement to include the Description from the related table in the query and you're done.
But, with the object design chosen in the CMS this won't work as the
Content item only exposes a ContentTypeId, not a ContentType object or something like that.

There are a few approaches to this. One is indeed to fire a query for each and every item in the Grid. However, this feels weird, for both in the code you have to write and in the performance hit you have to accept.

An alternative is to give the Content class a ContentTypeDescription property (besides the ContentTypeId) that holds the Description of the ContentType. At load time the property is filled with the category name and later displayed in the Grid directly.
Works fine, and doesn't give you the performance hit of scenario 1 but it still feels weird to store more or less duplicate data (not really, but still...)

Another approach is taken in chapter 12 - The Wrox Bugbase. Each Bug has properties like Status, Severity, Reproducibility etc. Instead of simply holding a number (the primary key), these properties are of type NameValue, an object that exposes the primary key (Id) and a user-friendly Description. The user sees the description, while the database uses and stores the Id.

In my opinion, this is a clean solution. You still store some sort of derived data (that is, the running code doesn't need the Description, it's only used for display purposes), but because it's contained in its own object, it's much cleaner.

One downside with this solution is with two-way databinding. ASP.NET has problems to use complex objects and their properties as properties in a databinding scenario. So, it's easy to bind, say, Bug.Title to a TextBox, but it requires manual code to work with something like Bug.Severity.Id and Bug.Severity.Description.

A bit of a long post, but hopefully it helps you in understanding the different options you have.

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.
  #8 (permalink)  
Old October 2nd, 2006, 02:29 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the answers. During my research to find a solution to the problem I've noticed that ASP.NET seems to have some problem with handling objects since I found quite a few O/r-Mappers and other things to help handling objects. But I want to keep it simple and I really like the code used in this book. I havent gone through all the chapters in the book yet but the next chapter I'm gonna look at is 12 to see the solution there.
Thanks again.

  #9 (permalink)  
Old October 2nd, 2006, 04:43 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's me again. Sorry for asking so much. The NameValue solution works excellent and solved a few of my problems but theres still some things I can't figure out. Say you wanted to get two or more values out of a related table, for instance the application description and the isActive value. How to do that? Where do I draw the line to create an object of a table and when not to?

Why I ask so many questions is that I like this code and trying to apply it on a bit larger database and to get the concepts on how this would work. As I see it the problem occurs when I have to large tables that are related to each other and where I want to get information from both to put in a list. Both these tables are used as objects. I understand that I can go far by using a sitestructure that only uses an object a time but if you have som tips on the problem it would be much appreciated.

  #10 (permalink)  
Old October 3rd, 2006, 02:23 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Hyzac,

Don't worry about asking too many questions; that's the whole purpose of this forum, and especially if it's about a Wrox book... ;)

Anyway, I think if you want to stick to OO principles, you reach the point where you change a simple property into an object pretty quick. Obviously, it all depends on your preferences, knowledge, database schema and so on, but there is nothing wrong about creating objects with properties that are other objects or even collection of those objects.

I recently designed and help develop a large and clean framework on top of a broken CRM system. From a high level perspective, the system deals with "simple", real world objects like a Person, an Organization and so on. Obviously, you can't give these objects properties like:
Code:
ShippingAddressStreet
ShippingAddressHouseNumber
VisitAddressStreet
VisitAddressHouseNumber
as the number of properties quickly becomes too large to manage in a logical way. So, we designed a number of other, smaller classes, like Address (with a Type, like Shipping and Visiting), a ContactRecord (for e-mail addresses, phone numbers and so on) and many other real world objects.

A Person or an Organization class then gets properties of these types, or even collections of these types, often in the form of a Generics list, like List<Address> or List (Of Address).

Some of these lists have smart properties, like a DefaultItem, that return specific items from the underlying collection. So, assuming a Person has a list of address records called Addresses and one of those items is marked as a default item, you could do something like this:
Code:
myPerson.Addresses.DefaultItem.Street
or
Code:
myPerson.Addresses[0].Street
Additionally you could create and assign an address like this:
Code:
Address myAddress = new Address();
myAddress.Street = "Some Street";
myAddress.HouseNumber = "Some Street";
myAddress.Type = AddressType.Shipping;
myPerson.Addresses.Add(myAddress);
When you save the person with Person.Save() you look at the Addresses collection, see if it's dirty and if it is, you save the items in the database. You store each address in an Address table, and link the address to the person in an PersonAddress junction table. At load time (in a static Person.GetItem(someId) method for example), you do the reverse: look at the junction table, find all associated address records in the Address table and dump them in the Person's Addresses collection.

(These are all just examples; there are many other ways to accomplish the same thing, but hopefully you can see where this is going.)

This leaves you with a clean and easy to understand object model. Without much training, other developers should be able to understand and use this model.

Now databinding, on the other hand is, a bit trickier. It's easy to pass these complex objects from a DAL or Business Layer up to the presentation layer, but then what? Binding the main Person properties to a GridView is simple as well; the GridView will do this automatically when you bind it to a collection of Person objects.
You should also be able to, say, display the Addresses in a nested Repeater for example with some databinding code in, again for example, a RowDataBound event.

I think two-way databinding is a lot trickier, or maybe even impossible. ASP.NET has serious problems in accessing these complex objects / properties. That is, it can set something like myPerson.FirstName for you, but it won't be able to set myPerson.Addresses[0].Street again based on a form variable.

One solution to overcome this is to use one-way databinding. You design a form that is capable of displaying the correct properties and collections for your object. When the Save button is clicked, you get another instance of the same object from the database, then overwrite relevant properties with new entries from the form, and save the item to the database. This additional call, that isn't needed in pure two-way databinding, is, IMO, well worth the cost. It does take additional round-trips to the database, but with increased flexibility.

You can do something like this to save a Person:
Code:
Person myPerson = Person.GetItem(myId);
myPerson.FirstName = txtFirstName.Text;

Address myAddress = new Address();
myAddress.Street = txtStreet.Text;
myAddress.HouseNumber = txtHouseNumber.Text;
myAddress.Type = (AddressType) lstType.SelectedValue;
myPerson.Addresses.Add(myAddress);
Again, just an example, but one that works for me. I am sure you have your own ideas and opinions that you want to want to blend in to this, together with opinions from co-workers or other resources, but hopefully this puts you a bit on track, inspiring you to create well-designed and easy to navigate object models and applications.

A bit of a long post again, but this is not easily explained in a few sentences.... ;)

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: She's Lost Control (12 inch) by Joy Division (Track 1 from the album: Heart And Soul (CD 2)) What's This?
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.