views:

35

answers:

2

Hi guys;

I have another conceptual question. Suppose I have a Data Layer and a Bussines Layer. I have on my data base for example Customers and those customers has an assigned Vendor:

Customers(customerID, customerName, customerAddress, vendorID)
Vendors(vendorID, vendorName, vendorAddress)

Now suppose my Vendor logs into my web application and wants to see all his customers:

a) Should I use my Datalayer method and there find his customers on the query?

b) Should the data layer return all the customers and on the Buissnes Layer filter that vendor ones?

Is B even a good approach because is the one I want to use.... Is it correct?

Thanks in advance!!!

+3  A: 

Is B even a good approach because is the one I want to use.... Is it correct?

If you want to use this approach, you can.

However, this does have a potentially huge disadvantage. By forcing the data layer to return all of the customers, and pass them into the business layer, you're going to load every customer for a query that, in essence, may only require a few customers.

This could dramatically increase the resource usage of your system.

If you provide a method by which the business layer can query the data layer directly for just those required customers, you'll push the query into the database, and prevent ALL of the customers from being loaded and sent between layers. This will be much more scalable, since the DB can do a much better job of this query, and no transmission is required for the extra "throw-away" data.

Reed Copsey
+2  A: 

If you're dead set on doing a large load, I would at least go with a lazy/demand initialization pattern like:

namespace BL
{
    public class Vendor
    {
        private Dictionary<CustomerKey, Customer> customers;
        public Dictionary<CustomerKey, Customer> GetCustomers(bool bDemandRefresh)
        {
            if (customers == null || bDemandRefresh == true) customers = DL.Customer.GetCustomersByVendor(vendorKey);
            return customers;
        }
    }
}