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

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

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.
 
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.
 
Back
Top