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 June 16th, 2008, 07:42 AM
Registered User
 
Join Date: Jun 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Orders listing web service

Hello everyone,
Congratulations on this great forum. Great book, too.
I have a general question about TBH architecture. I'd like to know which way is best to efficiently handle one-to-many relationships in such a system. More specifically:
You are to develop a web service (ws) to allow authorized accounts to retrieve a listing of confirmed orders placed between two given dates. Such listing needs to retrieve all order items for each order. From the ws perspective, all it takes is a Order.GetOrders() call to be serialized. Let's take a look at how it would work:
As it is, TBH would first retrieve a list of DAL.OrderDetails from the DAL, pass it to the BLL, and parse them into a list of BLL.Store.Order objects. For each Bll.Order object, TBH loads a list of dependent Bll.OrderItem objects, which requires a new connection to the DB server to retrieve a listing of order-dependent Dal.OrdenItemDetails objects to be parsed into a list of Bll.OrderItem objects. (Let's ignore Bll.BizObject.Cache for now.)
We are talking a number of DB connections equal to 1 + the total no. of orders retrieved. While this may not be a big problem for a small-sized website, I don't think this is a scalable solution. From an architectural point of view, what would be a standard approach to such a requirement?
Some ideas would be to add a OrderItemDetails[] member to Dal.OrderDetails and create some methods (or add some method overloads) that retrieve two recordsets on a single DB server call. The first recordset would list all orders, and the second one would include all order items. The second recordset entries need to be sorted just as the first recordset was, to allow for efficient data parsing:
Code:
public override List<OrderDetails> GetOrders
    (int statusID, DateTime fromDate, DateTime toDate bool includeOrderItems)
{
if(!includeOrderItems) return GetOrders(statusID, fromDate, toDate);
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
/* Place SqlCommand logic here */
List<OrderDetails> orders = [we parse the first recordset];
if(orders.Count>0)
{
    int orderIndex = 0;
    OrderDetails currentOrder = orders[0];
    while(secondRecordset.Read())
    {
        OrderItemDetails itemDetails=ParseOrderDetails(secondRecordset);
        while(itemDetails.OrderID!=currentOrder.ID) currentOrder=orders[++orderIndex]; 
        // hence the need for analog sorting
        currentOrder.OrderItems.Add(itemDetails);
    }
}
return orders;
}
}
When calling BLL.Store.Order.GetOrderFromOrderDetails(OrderDeta ils record), TBH should check whether the record contains subitems. When true, the usual call to SiteProvider.Store.GetOrderItems(record.ID) should be bypassed.
Alternatively, you could simply use an out List<OrderItemDetails> parameter and do the subitems population inside the Bll. This approach prevents having to add new members to the Dal.OrderDetails class.
What I'd like to know is what would be a standard approach according to TBH architecture (I am a self-taught programmer), be it this proposal, or an entirely different one. Also, while the example is very specific, I'd like to know the usual approach to this kind of one-to-many relationships in similar n-tier systems. Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing 8-10 and Listing 8-16. Asp.Net BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 February 6th, 2008 01:11 PM
Web Service Consuming another web service CraigWhitfield EJB 0 January 10th, 2008 08:38 AM
Error to Add Web Reference from a Web service jdjbarrios ASP.NET 2.0 Professional 0 July 18th, 2006 02:58 PM
Service Oriented Web Service aldwinenriquez .NET Web Services 2 September 15th, 2005 03:25 AM





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