This code will work sometimes for some elements, but it always fails when trying to process more elements, and I would get the following: {"The underlying provider failed on Open."}exception
List<Recon> scenarioAll = db.Transactions
.Where(t => t.SrcObjTyp == "13")
.Select(t => t.Recon).ToList();
Parallel.ForEach(scenarioAll.Take(100), r =>
{
invoices = r.Transactions.SelectMany(t => t.InvoiceDetails).ToList();
CreateFacts(invoices, r).ForEach(f => facts.Add(f));
transactions = r.Transactions.Where(t => !t.SrcObjTyp.Contains("13")).ToList();
DistributeTransactionOnItemCode(transactions, facts);
Console.WriteLine(i += 1);
});
facts.ForEach(f => db.ReconFacts.Add(f));
db.SaveChanges();
I think issus is a multiple process that accesses the database at the same time, is it possible to allow EF to be requested by several processes this way?
There is also a way to load everything into memory, so when accessing a child Reconlike this, r.Transactions.SelectMany(t => t.InvoiceDetails).ToList();everything will be in memory and will not access the base database?
Which solution do you think is best?
source
share