Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a business object that is set up with some of it's properties being other business objects.

So something like
C#
AddressObject OrignAddress { get; set;}


When I am loading a list of this object from a Data Table Adapter the time it takes to return is 90 seconds or so with 1000 records. I am open to any and all suggestions on how to make this faster. If I remove the two lines that are adding the instance of Stops it returns much quicker. I have confirmed that there is nothing in the constructors of any of these that should be causing the slow load times. The full code is posted below:


C#
List<Loads> ldnireturn = new List<Loads>(dtLS.Rows.Count);
for (int x = 0; x < dtLS.Rows.Count; x++ )
{
 LoadsDS.LoadDeliveredNoInvoiceRow drLS = dtLS.Rows[x] as LoadsDS.LoadDeliveredNoInvoiceRow;

                ldnireturn.Add(new Loads
                {
                    LoadId = drLS.LOAD_ID,
                    TotalWeight = drLS.IsTOTAL_WEIGHTNull() ? 0 : drLS.TOTAL_WEIGHT,
                    Cost = drLS.IsTOTAL_COSTNull() ? 0 : drLS.TOTAL_COST,
                    StopOrigin = new Stops
                    {
                        Name = drLS.IsORIG_NAMENull() ? "" : drLS.ORIG_NAME,
                        City = drLS.IsORIG_CITYNull() ? "" : drLS.ORIG_CITY,
                        State = drLS.IsORIG_STATENull() ? "" : drLS.ORIG_STATE,
                        PostalCode = drLS.IsORIG_ZIPNull() ? "" : drLS.ORIG_ZIP
                    },
                    StopDest = new Stops
                    {
                        Name = drLS.IsDEST_NAMENull() ? "" : drLS.DEST_NAME,
                        City = drLS.IsDEST_CITYNull() ? "" : drLS.DEST_CITY,
                        State = drLS.IsDEST_STATENull() ? "" : drLS.DEST_STATE,
                        PostalCode = drLS.IsDEST_ZIPNull() ? "" : drLS.DEST_ZIP
                    },
                    Carrier = new CarrierObj { Name = drLS.CarrierName },
                    DeliveredDate = Utilities.SafeParse<DateTime>(drLS.DELIVERED_DATE),
                    LoadTenderDate = Utilities.SafeParse<DateTime>(drLS.LOAD_TENDER_DATE),
                    CarPro = drLS.IsCARPRONull() ? "" : drLS.CARPRO,
                    CarrierInvoiceID = drLS.IsCARRIER_INVOICENull() ? "" : drLS.CARRIER_INVOICE
                });
}
Posted
Comments
Chinmaya C 22-Apr-13 12:18pm    
do you have any constructors for Loads, Stops, and CareerObj classes?
and why don't you use DataReader instead of datatable. I believe datareader is faster than dataset.
Patrick Forsythe 22-Apr-13 13:05pm    
There are no constructors for those classes. Data table adapters are being used for all of our data objects at the moment.
tumbledDown2earth 22-Apr-13 12:42pm    
Can you debug a little and find the performance cone ... Try to identity while stepping through your code that which statement takes roughly the longest time ...

Your code can definitely be optimized, but its not the reason so such a delayed loading. I suspect your DA code has a long connection duration. Check/profile the connection.Open() statement and see
Patrick Forsythe 22-Apr-13 13:07pm    
The data access stuff is all handled through the data table adapter, I double checked the connection strings and we are not specifying any connection timeout or any info like that. One thing to note is that if I comment out the code that creates the Stops info it returns in under 10 seconds, and the query itself returns in under a second with all 7k+ rows using sql management studio.
tumbledDown2earth 22-Apr-13 23:15pm    
So how many rows are in the StopsInfo table then? Is the table indexed? Can you check the query in management studio and check how much time it takes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900