, когда я пытаюсь извлечь записи в асинхронной функции задачи из таблицы с использованием репозитория единицы работы, возникает исключение
"System.Data.Entity.Core.EntityException: сбой основного поставщикаon Open. ---> System.InvalidOperationException: Соединение не было закрыто. Текущее состояние соединения: «
var ProductList= unitOfWork.ProductRepo.Find(x => x.Id== ProductId);
, хотя я создаю новый объект unitofwork для каждой Задачи.но для одного потока это работает нормально.
full trace:"TRACE:Task.Execute => Task`1.InnerInvoke => <>c__DisplayClass17_0.<StartMigration>b__0
EXCEPTION:System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: The connection was not closed. The connection's current state is connecting.
at System.Data.ProviderBase.DbConnectionClosedConnecting.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.EntityConnection.<Open>b__2()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
--- End of inner exception stack trace ---
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
at FS.Migration.Assistant.Assistant.MigrationAssistance.<>c__DisplayClass17_0.<<StartMigration>b__0>d.MoveNext() in "
не весь код, который я могу вставить, вот фрагмент кода, где создается новое соединение с использованием DBconrtext для каждого запуска задачи
Task.Run(async () =>
{
Model.MigrationModel.ReadyToMigrate ready = new ReadyToMigrate();
unitOfWork = new UnitOfWork(new ContextMigrationEntities());
try
{
}Catch(Exception ex)
{
}
});