I am trying to migrate from ef6 to ef core and started getting below problems
System.InvalidOperationException: 'A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext, however instance members are not guaranteed to be thread safe. This could also be caused by a nested query being evaluated on the client, if this is the case rewrite the query avoiding nested invocations.'
on:
_dbContext
.Query<EntityModel>()
.FromSql(query, new SqlParameter("@userId", userId))
.ToList();
I solved this once by adding MultipleActiveResultSets=true to the connectionstring.
Example:
string connectionString = "Data Source=MSSQL1;" +
"Initial Catalog=AdventureWorks;Integrated Security=SSPI;" +
"MultipleActiveResultSets=True";
Just add it in your appsettings.json connectionstring