Which is faster? Array Struct or DataTable

I use LinqToSQL to process data from SQL Server to dump it to the iSeries server for further processing. Read more about it here .

My problem is that it takes about 1.25 minutes to process these 350 rows of data. I'm still trying to decrypt the results from SQL Server Profiler, but there are TON queries that are running. Here are some details about what I am doing:

using (CarteGraphDataDataContext db = new CarteGraphDataDataContext())
{
    var vehicles = from a in db.EquipmentMainGenerals
                   join b in db.EquipmentMainConditions on a.wdEquipmentMainGeneralOID equals b.wdEquipmentMainGeneralOID
                   where b.Retired == null
                   orderby a.VehicleId
                   select a;

    et = new EquipmentTable[vehicles.Count()];

    foreach (var vehicle in vehicles)
    {
       // Move data to the array

       // Rates
       GetVehcileRates(vehicle.wdEquipmentMainGeneralOID);

       // Build the costs accumulators
       GetPartsAndOilCosts(vehicle.VehicleId);
       GetAccidentAndOutRepairCosts(vehicle.wdEquipmentMainGeneralOID);

       // Last Month Accumulators
       et[i].lastMonthActualGasOil = GetFuel(vehicle.wdEquipmentMainGeneralOID) + Convert.ToDecimal(oilCost);
       et[i].lastMonthActualParts = Convert.ToDecimal(partsCost);
       et[i].lastMonthActualLabor = GetLabor(vehicle.VehicleId);
       et[i].lastMonthActualOutRepairs = Convert.ToDecimal(outRepairCosts);
       et[i].lastMonthActualAccidentCosts = Convert.ToDecimal(accidentCosts);

       // Move more data to the array

       i++;
   }
}

Get methods all look something like this:

private void GetPartsAndOilCosts(string vehicleKey)
{
   oilCost = 0;
   partsCost = 0;

   using (CarteGraphDataDataContext db = new CarteGraphDataDataContext())
   {
      try
      {
         var costs = from a in db.WorkOrders
                     join b in db.MaterialLogs on a.WorkOrderId equals b.WorkOrder
                     join c in db.Materials on b.wdMaterialMainGeneralOID equals c.wdMaterialMainGeneralOID
                     where (monthBeginDate.Date <= a.WOClosedDate && a.WOClosedDate <= monthEndDate.Date) && a.EquipmentID == vehicleKey
                     group b by c.Fuel into d
                     select new
                            {
                                isFuel = d.Key,
                                totalCost = d.Sum(b => b.Cost)
                            };

          foreach (var cost in costs)
          {
             if (cost.isFuel == 1)
             {
                oilCost = (double)cost.totalCost * (1 + OVERHEAD_RATE);
             }
             else
             {
                partsCost = (double)cost.totalCost * (1 + OVERHEAD_RATE);
             }
          }
       }
       catch (InvalidOperationException e)
       {
          oilCost = 0;
          partsCost = 0;
       }
    }

    return;
 }

My thinking here minimizes the number of database queries to speed up processing. If LINQ does a SELECT for each record, perhaps I need to load each record into memory first.

# OOP ( RPG iSeries). , - . ( , )?

: , , . , . , LINQ , . , LINQ , . . XSD 1,25 15 . , , . . LINQ .

+5
1

, :

  • "var cars", , .
  • , select. LINQ to SQL . : select new { a.VehicleId, a.Name }
  • GetPartsAndOilCosts , cost.totalCost * (1 + OVERHEAD_RATE) LINQ. , , .
  • Count() var vehicles, . LINQ to SQL SELECT count(*) , . ( ) . , ArrayIndexOutOfBoundsException. .ToArray() List<EquipmentTable> .ToArray(). , 380 , , , , ().
  • , , , . struct DataTable .
  • , , , ( SQL) . , .

№ 1. , :

var query = from x in A select something;

foreach (var row in query)
{
    var query2 = from y in data where y.Value = row.Value select something;

    foreach (var row2 in query2)
    {
        // do some computation.
    }
}

, query2, . , - :

var query =
    from x in A
    from y in B
    where x.Value == y.Value
    select something;

foreach (var row in query)
{
}

, , ( ). , . , , LINQ to SQL ( ).

, , Stackoverflow, , , , - ( ):-) .

+7

All Articles