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 August 3rd, 2007, 09:19 AM
Registered User
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Database Design Question about WebShop

I used the same tables as in the webshop solution of chapter 9.
However, I added a manufacturer table.

The category table has a 1:M relationship with the products table.
The manufacturer table has a 1:M relationship with the products table.

I need to create a relationship between the category and manufacturer table.

Should I create a table called ManufacturerCategory that connects the category and manufacturer table?


 
Old August 3rd, 2007, 09:44 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

If a Category is produced by more than one manufacturer, then yes. Otherwise, storing the ManufacturerId in the Category would be enough....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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 August 3rd, 2007, 10:05 AM
Registered User
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your help and fast response Imar. Instant Results is a great book. I also frequent your website and read your articles.
Please keep up the good work.
                   Wayne

 
Old August 3rd, 2007, 10:59 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome. Glad you like the book.

Have fun!!

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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 August 4th, 2007, 10:15 AM
Registered User
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar, I'm dealing with a many to many relationship between category and manufacturer. In my code do I need to create a hybrid class that combines the private fields and public properties of the manufacturer class and category class or is there another way?

example
public class Manufacturer
private int _id;
private string _name;

public class Category
private int _id;
private string description;

public class ManufacturerCategory
private int _categoryID;
private int _manufacturerID;
private string _name;
private string description;

Only problem with this is shouldn't you avoid duplicate code when your able to?



 
Old August 4th, 2007, 11:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, you don't necessarily need to replicate the database behavior in your object model. What about this:

public class Manufacturer
{
  private int _id;
  private string _name;
  private List<Category> _categories;
}

public class Category
{
  private int _id;
  private string description;
  private List<Manufacturer> _manufacturers;
}

This gives each class a generics list of the other, allowing you to do stuff like:

myGridView.DataSource = myCategory.Manufacturers;

or

myManufacturer.Categories.Add(new Category());

This brings some other interesting issues about loading data. E.g. when you load a Manufacturer, do you load all Categories? Probably not, because it means you load all categories, in turn loading all the associated manufacturers for the category, in turn loading all the categories and so on.

For this scenario, you may want to use a concept called lazy loading where you defer loading the data until you actually access it.

With regards to your ManufacturerCategory class: the rules of normalization that apply to databases do not apply to object models. That is, it's OK to have duplicate data in your object model, as long as you don't store it in duplicate fields / tables in the database. With an object model, it's important to normalize behavior, not the underlying data.

Hope this gives you some ideas.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 4th, 2007, 12:17 PM
Registered User
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Once again thanks for the ideas Imar. Your input is greatly appreciated.

 
Old August 8th, 2007, 06:10 PM
Registered User
 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not quite sure how to retrieve data from method in DAL.
CategoryDetails and BrandDetails are BO classes that just contain private fields and public properties. Each BO class has the other BO class as a public generic collection property. I know you said to implement lazy loading but I'm having too much trouble just getting my method to return data from both tables Brand and Category.

The stored procedure works correctly not for certain how I retrieve data from two different tables. CategoryID, Title are in the Category table and BrandID and BrandName are in the Brand table.

public List<CategoryDetails> GetCategoriesByBrand(int brandID)
        {
            List<CategoryDetails> list = new List<CategoryDetails>();

            using (SqlConnection cn = new SqlConnection(this.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("vcs_GetCategoriesByBrandID", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("BrandID", SqlDbType.Int).Value = brandID;
                cn.Open();
                SqlDataReader r = cmd.ExecuteReader();
                CategoryDetails category;
                while (r.Read())
                {
                    category = new CategoryDetails((int)r["CategoryID"],
                      (string)r["Title"]);

                    category.Brands.Add(new BrandDetails((int)r["BrandID"], (string)r["BrandName"]));
                    list.Add(category);
                 }
                cn.Close();
            }
            return list;
        }

 
Old August 9th, 2007, 01:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

And what is the problem? The code you posted could theoretically work, so I don't see any problem with it....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004





Similar Threads
Thread Thread Starter Forum Replies Last Post
WebShop (Chap 9) Question about Login SDonnelly BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 October 19th, 2006 04:12 AM
WebShop (Chap 9) Question SDonnelly BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 18 May 23rd, 2006 11:33 AM
Question about Logical database design in ERwin method SQL Server 2000 3 November 24th, 2005 12:38 PM
Design Question flyin General .NET 4 July 21st, 2004 03:59 PM





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