What would be the recommended class design to get a customer and their orders? For example one customer has two orders. Returned data would look like
CustID Name Address OrderID OrderName OrdDescription
1 Bob UK 1234 ASP Book ASP .Net in 24 Hours
1 Bob UK 4321 WCF Book WCF in 24 hours
So i have a query which does all the work in retrieving the data.
I could have a class which has the Customer table fields as properties and then have a list of Orders (List (OF Orders))
or
I could have a class which has the Customer table fields as properties and then have a list of Orders (List (OF Orders)) but pass in the CustomerID into the orders table and then display it.
Both ways have their ups and downs (one gets the data in one attempt while the second makes a second call). Which would be appropriate to use to avoid future issues?
I've removed many bottle necks from systems by getting all the data at once. Don't forget to left join the orders just in case the customer has no orders.
Future issues are hard to predict. I just wish I had know earlier that formating websites with tables was a big taboo.
In that case would I retrieve the data and store it in a CustomerOrders data table then have a for each to see if they have multiple orders if so insert those orders into a List? Thanks
Both ways have their ups and downs (one gets the data in one attempt while the second makes a second call). Which would be appropriate to use to avoid future issues?
strictly speaking it depends on how you would show on UI....if you want to show all the data at once in UI, then you need to get them at once....but if you have flexibility of showing only cust data preliminarily and then get the other data later, then you
can Lazy load orders list using Lazy<T>...so still you can go for your first approach....
When the customer name and details loads i would like to show the orders too at the same time.
If i load the details in one attempt then i would have two rows - i dont want to display the customer details twice if there are two orders but display the two orders with the customers details once.
So if i return two rows back as above my question would be if i have a datatable with the details loaded how could i load the customer details into the class once but adding all the orders?
EssCee
Member
548 Points
760 Posts
Class design and database question
Feb 21, 2013 07:30 PM|LINK
What would be the recommended class design to get a customer and their orders? For example one customer has two orders. Returned data would look like
CustID Name Address OrderID OrderName OrdDescription
1 Bob UK 1234 ASP Book ASP .Net in 24 Hours
1 Bob UK 4321 WCF Book WCF in 24 hours
So i have a query which does all the work in retrieving the data.
I could have a class which has the Customer table fields as properties and then have a list of Orders (List (OF Orders))
or
I could have a class which has the Customer table fields as properties and then have a list of Orders (List (OF Orders)) but pass in the CustomerID into the orders table and then display it.
Both ways have their ups and downs (one gets the data in one attempt while the second makes a second call). Which would be appropriate to use to avoid future issues?
Thanks
Danny117
Star
11160 Points
1932 Posts
Re: Class design and database question
Feb 21, 2013 08:16 PM|LINK
I've removed many bottle necks from systems by getting all the data at once. Don't forget to left join the orders just in case the customer has no orders.
Future issues are hard to predict. I just wish I had know earlier that formating websites with tables was a big taboo.
Me on linked in
EssCee
Member
548 Points
760 Posts
Re: Class design and database question
Feb 21, 2013 09:16 PM|LINK
EssCee
Member
548 Points
760 Posts
Re: Class design and database question
Feb 22, 2013 09:30 PM|LINK
ramiramilu
All-Star
95463 Points
14106 Posts
Re: Class design and database question
Feb 23, 2013 05:04 AM|LINK
strictly speaking it depends on how you would show on UI....if you want to show all the data at once in UI, then you need to get them at once....but if you have flexibility of showing only cust data preliminarily and then get the other data later, then you can Lazy load orders list using Lazy<T>...so still you can go for your first approach....
thanka,
JumpStart
EssCee
Member
548 Points
760 Posts
Re: Class design and database question
Feb 23, 2013 08:22 AM|LINK
When the customer name and details loads i would like to show the orders too at the same time.
If i load the details in one attempt then i would have two rows - i dont want to display the customer details twice if there are two orders but display the two orders with the customers details once.
So if i return two rows back as above my question would be if i have a datatable with the details loaded how could i load the customer details into the class once but adding all the orders?
Thanks again