Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    WeirdWes
    WeirdWes's Avatar
    Guest

    ASP.NET Object Oriented Programing - Linked Object Reporting?

    I'm developing an ASP.NET application, for the first time from the ground up. I've been doing web development for 4 years, but our shop is classic ASP based with a SQL backed. We've begun migrating to ASP.NET but we're not really using it to it's fullest because we're still doing the backend using SQL which just sends datatable to the presentation layer for rendering, meaning we're not using the OOP approach and propery 3-Tier design.

    So now that I am going down this road, I have a question. Suppose I have two business objects that are related, e.g., a Customer and a Shipping Address. The customer has properties such as Name, Race, Gender, Age and the Shipping Address would have your commen properties such as Street Address, City, State, Zip, Country.

    Now then, the Customer object also has a property called ShippingAddress which is obviously enough, a ShippingAddress object. When I instantiate my Customer Object, I am also instantiating a new instance of ShippingAddress and supplying all of it's field. This seems straight forward enough.

    But now my dilema is this - suppose I have a shipping summary page that a list of every customer who has been shipped an order that day, but it's only display their last name and street address (no city, state or zip) and suppose this report has several hundred people on it. Because I do not need the extra overhead of the customers Age or Race and I also do not need the overhead of their Shipping Address' City, State, Zip - how do I go about supply this report with the correct objects?

    Do I instantiate the objects as-is and do not supply those properties with data?

    Do I instantiate the objects as-is supplying all day, incurring the overhead, but not rendering the data on the report?

    Do I create a new object(s), that has only the data this report needs and instantiate those instead?

    I have no formal training in OOP, and most peopel tell me there is no best practice for this kind of thing, but I'd have to imagine there are people who have ran into this before and I'd like to know what some of your solutions have been.

    Thanks!

  2. #2
    dhvrm
    dhvrm's Avatar
    Guest
    You're making this a lot more complicated than it need be.

    Assuming you're a normal developer who has created the type of tables that are common, you have a table that contains customer names and perhaps a table that contains address information.

    The address table has a foreign key that relates to the customer table's primary keys: That is, customer record 1 may have three or four addresses, but each of those address records has a customer key of 1.

    In the order table, each order record need contain two foreign keys -- one for the customer id, the other for the shipping address id.

    Then, when you want to create your report, you simply supply a SQL query that gives you the appropriate fields, e.g.:

    SELECT c.last_name, a.street_address, o.id FROM orders AS o INNER JOIN customers AS c ON o.customer_id = c.id INNER JOIN addresses AS a ON o.shipping_id = a.id

    And, provided you have properly keyed everything, you only get what you want.

    That said, you can work with more complex objects using the ADO.NET Entity Framework.

    http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx

    Again, I think that's huge overkill, given that the traditional approach works fine, but it is an option.

 

 

Quick Reply Quick Reply

Click here to log in


What comes after M0nday

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 09-09-2011, 12:00 AM
  2. Replies: 0
    Last Post: 02-22-2011, 04:14 AM
  3. Replies: 0
    Last Post: 01-07-2011, 08:29 AM
  4. Replies: 0
    Last Post: 12-07-2010, 04:41 AM
  5. Replies: 0
    Last Post: 08-01-2009, 06:52 PM

Bookmarks

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •