.NET
  Home arrow .NET arrow Page 4 - Creating the Home Page for a Simple Storef...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Creating the Home Page for a Simple Storefront with LINQ
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-05-06

    Table of Contents:
  • Creating the Home Page for a Simple Storefront with LINQ
  • ItemTemplate
  • A New Style
  • Preparing to Build the Product Page

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating the Home Page for a Simple Storefront with LINQ - Preparing to Build the Product Page


    (Page 4 of 4 )

    Now we can create Product.aspx, the page where the details of an individual product can be viewed. Go ahead and create Product.aspx. Make sure you set MasterPage.master as its master page.

    Before we do anything, recall that the description of a product is not in the Product table. Rather, descriptions are associated with models through the ProductModelProductDescription table. So, in order to get the description of an item, we need to first determine a product's model. It's a long trail, though. We need to go from Product to ProductModel to ProductModelProductDescription to ProductDescription. We need to add these tables to AdventureWorks.dbml before we continue with the Product.aspx page:


    Now, pay attention to the direction of the arrows, which represent associations. Notice how the arrow between ProductModel and ProductModelProductDescription is pointed away from Product, while every other arrow is pointed toward Product. This is because ProductModel is set as the parent class, and ProductModelProductDescription is set as the child class. Basically, the two terms involve how each table handles the field around which the association is built. With ProductModel and Product, for example, the association is built around ProductModelID. In the ProductModel table, this field is the primary key, and in Product, it's just a normal field. So, ProductModel is the parent class here. However, with ProductModelProductDescription and ProductModel, both tables have ProductModelID as a primary key, so either table can be the parent class.

    For our purposes, the association is backward, though. The association suggests that more than one entry in the ProductModelProductDescription table (the child table) can be matched with a given ProductModelID (part of the parent table), just as more than one entry in the Product table can be matched with a given ProductModelID (part of the parent table). It's entirely possible for us to build our application with this configuration, but then to access the ProductDescription for a given Product (p), we have to use First, which is ugly and troublesome:

    p.ProductModel.ProductModelProductDescriptions.First().ProductDescription.Description


    Fixing this is easy. Click the arrow and delete it to delete the association. Then, right click the Designer and add a new association. Set ProductModelProductDescription as the parent and ProductModel as the child. Then, select the ProductModelID property for both of them:



    Now all of the arrows face the same direction:





    This makes more sense: while every ProductDescription can be matched with multiple Product entries, every Product can only be matched with one ProductDescription. Now we can drop the call to First when accessing a Product's description:

    p.ProductModel.ProductModelProductDescriptions.ProductDescription.
    Description

    This is a lot more logical.

    We're almost ready to begin work on Product.aspx. Just add one final style definition to StyleSheet.css, and we'll be ready to start work:


    .itemBoxLarge

    {

     background-color: #F0FFFF; /* Azure */

     border: solid 1px Orange;

     margin: 5px auto 0px auto;

     padding: 5px;

     text-align: left;

     width: 70%;

    }

    Don't forget to check back next week for the third part of this three-part series!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello, all. This short series shows off some of the capabilities on LINQ by building...
     

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT