I've got a console line application that saves approximately 150,000 rows to the database through LINQ. This works fine (where I would normally expect it to stop working). It's a bog standard save changes call after reading data from the CSV file:-
List<Invoice> oldInvoices = db.Invoices.Where(x => !x.IsVisible).ToList();
List<int> oldInvoiceIDs = oldInvoices.Select(s => s.InvoiceID).ToList();
List<InvoiceProduct> allInvoiceProducts = db.InvoiceProducts.ToList();
List<InvoiceProduct> oldInvoiceProducts = allInvoiceProducts.Where(x => oldInvoiceIDs.Contains(x.InvoiceID)).ToList();
db.InvoiceProducts.RemoveRange(oldInvoiceProducts);
db.Invoices.RemoveRange(oldInvoices);
UpdateConsole.WriteLine("Switching over invoices completed. Please wait...", ConsoleColor.Black, ConsoleColor.Magenta);
The table is a list of invoices with a sub-linked table of products against each invoice. Each time we get new data, we write in the new data, mark it in the database as not visible, then switch the currently visible data to invisible and the currently invisible data to visible, giving the effect of an immediate switch from one dataset to the next dataset. The dataset that just got marked as invisible then gets deleted through LINQ.
This takes its time to delete, but not an unreasonable amount of time. As this data comes from a CSV data file, we log the number of rows, and start and end date and time of the reading of the file. This is stored in another database table and the code to save is:-
importLog.SuccessfullyImportedRows = successfulRows;
importLog.FailedImportedRows = failedRows;
importLog.EndTime = DateTime.Now;
db.SaveChanges();
This save, takes in excess of 40 minutes and I've no idea why. The only thing I can think of is that it is using the same DBEntities class that is made available when generated the EDMX in Visual Studio?
Has anyone had this? It give the appearance of the application hanging, but it does continue after 40 minutes or so...