当前位置: 动力学知识库 > 问答 > 编程问答 >

entity framework - Tasks with new Devart backed DbContexts raise errors

问题描述:

I have been pulling my hair on this one for a while now:

When i use the DbContext backed by the Devart DB2 provider in several tasks i get a NullReferenceException with the following stacktrace:

at Devart.Data.DB2.DB2ParameterCollection.Clear()

at Devart.Data.DB2.Entity.v.g()

at System.Data.Entity.Core.Common.DbProviderServices.CloneDbCommand(DbCommand fromDbCommand)

at System.Data.Entity.Core.Common.DbCommandDefinition.CreateCommand()

at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.PrepareEntityCommandBeforeExecution(EntityCommand entityCommand)

at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)

at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()

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.Infrastructure.DefaultExecutionStrategy.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.Buffer`1..ctor(IEnumerable`1 source)

at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)

I do spawn several new Contexts, but using the same login to one database, with each method started with Task.Factory.StartNew and they all start colliding with the error above.

I checked the contexts created and they all get a new id so i'm not reusing the same one in any way.

When i run them in order, one after the other, no problem.

Even when i run other in parallel with another login, no problem.

Have anyone seen something like this before?

网友答案:

This was casued by a bug in the dotConnect for DB2 by Devart

It was fixed 11th of feb 2016, but took a long time until i realized that thanks to the lack of nuget support by Devart :(

https://www.devart.com/dotconnect/db2/revision_history.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: