Last post Nov 22, 2010 09:34 PM by stephenmbell
Nov 22, 2010 02:34 PM|stephenmbell|LINK
I am seeing some performance issue with some of my custom business objects and I am wondering what you would recommend.
I am using the N-Layered Web Applications with ASP.NET 3.5 approach provided by Imar Spaanjaars on his website (imar.spaanjaars.com).
A brief explanation - assume I have an object of type Order. Order has the following properties:
- represents the id of a DeliveryDriver. DeliveryDriver is a custom type - DeliveryDriver, has Id and Name)
- represents the id of a ProductSupplier. ProductSupplier is a custom type - supplier, has Id and Name)
ProductsOrdered (custom type - a collection of custom type Product, has Id, UPC, Name, Price)
Currently, I display a combination of this information in a GridView, I bind the grid to a collection of Order objects. Currently in the RowDataBound event of the gridview I get my Order object by e.Row.DataItem. From here, I go to the database and effectively
call GetDeliveryDriver(myOrder.DeliveryDriver), and I call GetProductSupplier the same way.
In a grid with 100 orders in it, this is proving to be a lot of overhead, 2 methods that go to the db, connect, run a stored proc, populate the objects for EACH ROW.
What would you do to make this more efficient? I thought about rather than having the DeliveryDriver and ProductSupplier properties of the Order object be an int, I would make them the objects themselves (DeliveryDriver and ProductSupplier). I already
have methods written like GetDriver and GetProductSupplier - the problem I see with these is that they create a connection and open it... so wouldn't this be the same as doing it in the RowDataBound event?
Hope this makes sense
thanks for any replies
Nov 22, 2010 06:40 PM|sansan|LINK
If oders, products and drivers tables have relationships, you can join products and drivers table with orders to get the details. No need to call DB for every row which is not advisable
FROM ORDERS A
INNER JOIN DELIVERYDRIVER B ON A.ID=B.ID
INNER JOIN PRODUCTSUPPLIER C ON A.ID=C.ID
Nov 22, 2010 09:34 PM|stephenmbell|LINK
Thank you for the reply.
Yes, I am familiar with and use joins in my SQL code.
So if I were to store the drivername property of the order object as a string, when a user clicks to edit a particular row, and in the edit template the driver column contains a drop down list - how would I set the value??