SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the session

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the session

Message par Clippy »

SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the session
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: SqlException from Entity Framework - New transaction is not allowed because there are other threads running in the session

Message par Clippy »

After much pulling out of hair I discovered that the `foreach` loops were the culprits. What needs to happen is to call EF but return it into an `IList` of that target type then loop on the `IList`.

Example:

```
IList clientList = from a in _dbFeed.Client.Include("Auto") select a;
foreach (RivWorks.Model.NegotiationAutos.Client client in clientList)
{
var companyFeedDetailList = from a in _dbRiv.AutoNegotiationDetails where a.ClientID == client.ClientID select a;
// ...
}

```
Répondre

Revenir à « .NET & C# »