jeudi 24 décembre 2015

.NET c# How to mass insert with linq2db?

Currently im using Linq2db for managing my sqlite db with my C# application. For now im reading an excel file with 24k+ rows and im wondering how could i fast up my ETL proccess?

for (int row = start.Row; row <= end.Row; row++)
        {
            if (row == 1) // Title row
                continue;

            Stock stock = new Stock(Processor.GetStore(workSheet.Cells[row, 1].Text),
                            Processor.GetProduct(workSheet.Cells[row, 2].Text),
                            int.Parse(workSheet.Cells[row, 6].Text),
                            int.Parse(workSheet.Cells[row, 7].Text),
                            int.Parse(workSheet.Cells[row, 8].Text), 0, true);

            Processor.AddStock(stock, false);

        }

Tried a different approach using linq but i got worse timing results...

            var stocks = (from cell in workSheet.Cells["a:h"]
                      select new Stock(Processor.GetStore(workSheet.Cells[cell.Start.Row, 1].Text),
                            Processor.GetProduct(workSheet.Cells[cell.Start.Row, 2].Text),
                            int.Parse(workSheet.Cells[cell.Start.Row, 6].Text),
                            int.Parse(workSheet.Cells[cell.Start.Row, 7].Text),
                            int.Parse(workSheet.Cells[cell.Start.Row, 8].Text), 0, true)).ToList();

What i am looking for is something like this:

public static void MassStockInsert(List<Stock> stocks)
    {
        using (var db = new Processor())
        {
            db.Stock
                .insert(stocks);
        }
        Processor.Stocks = ReloadStocks();
    }

Aucun commentaire:

Enregistrer un commentaire