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

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.
 
S

sloan

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top