DAL, design question, what is best practice doing this?

Discussion in 'ASP .Net' started by Jeff, Oct 12, 2008.

  1. Jeff

    Jeff Guest

    hi

    asp.net 2.0

    I have a database here containing 2 tables, Order and OrderLines. OrderLines
    has a foreign key to Order...

    Until know I have created an entity class for Order (public class Order, not
    using DataSet), containing only the fields available in the Order table.
    But now I often need to know how many OrderLines are linked to a specific
    Order.

    So I thought about adding a int Count field to the Order entity. So when I
    run the stored procedure returning the Order, it has to do a count on
    OrderLines connected to this Order. But not sure that is best practice,
    because when I create a new Order I must set this value to 0. And also the
    Count field is not a real field in the Order table.

    Maybe there is an even better approach? Can I create a Order entity having
    links to OrderLines entity? Then maybe my Order entity could have a
    OrderLine collection property...?

    any suggestions? links to articles would be great.
     
    Jeff, Oct 12, 2008
    #1
    1. Advertisements

  2. Jeff

    sloan Guest

    Check



    Custom Objects and Tiered Development II // 2.0


    and find:
    http://sholliday.spaces.live.com/feed.rss


    When you have "sometimes I want OrderLines with Orders, sometimes I don't",
    I create different methods on the OrderController class.
    This lets me fine tune what I need, instead of having "If I instantiate a
    Order, bring in all OrderDetails" (or throwing crappo flags at it saying
    "Yes, include OrderLines, No..don't include OrderLines".

    ...

    OrderController.GetAllOrdersWithOrderLines();
    (and similar) is my preferred approach.
     
    sloan, Oct 12, 2008
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.