노력이 던졌습니다 InvalidOperationException : 시퀀스가 ​​두 개 이상의 일치하는 요소를 포함

c# effort entity-framework

문제

나는 연결을 생성하고 그것을 DB Context에 전달함으로써 일반적인 방법으로 노력을 사용하고있다 :

public class InMemoryContextInitializer
{
    public void BeforeAllTests()
    {
        Effort.Provider.EffortProviderConfiguration.RegisterProvider();
    }

    public DbConnection BeforeEachTest()
    {
        return Effort.DbConnectionFactory.CreateTransient();
    }

    public void AfterEachTest(DbConnection prevUsedConnection)
    {
        prevUsedConnection.Dispose();
    }
}

그리고 이런 식으로 :

    private static InMemoryContextInitializer _testHarness;
    private DbConnection _conn;
    private MyDbContext _myContext;

    [ClassInitialize]
    public static void BeforeAllTests(TestContext testCtx)
    {
        _testHarness = new InMemoryContextInitializer();
        _testHarness.BeforeAllTests(); // registers provider
    }

    [TestInitialize]
    public void BeforeTest()
    {
        _conn = _testHarness.BeforeEachTest();
        _myContext = new MyDbContext(_conn);
    }

    [TestCleanup]
    public void AfterTest()
    {
        _testHarness.AfterEachTest(_conn);
    }

내 모든 노력 테스트는 다음을 제외하고는 아무 문제가 없습니다.

System.Data.DataException: An exception occurred while initializing the database. See the InnerException for details. ---> 
System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> 
System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 
NMemory.Exceptions.NMemoryException: Error code: GenericError ---> 
System.InvalidOperationException: Sequence contains more than one matching element

    at System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source, Func`2 predicate)
   at NMemory.Tables.TableCollection.FindTable(Type entityType)
   at NMemory.Utilities.TableCollectionExtensions.FindTable(TableCollection tableCollection)
   at NMemory.Execution.CommandExecutor.ExecuteInsert(T entity, IExecutionContext context)
   at NMemory.Tables.DefaultTable`2.InsertCore(TEntity entity, Transaction transaction)
   at Effort.Internal.DbManagement.Engine.ExtendedTable`2.InsertCore(TEntity entity, Transaction transaction)
   at NMemory.Tables.Table`2.Insert(TEntity entity, Transaction transaction)
 --- End of inner exception stack trace ---
    at NMemory.Tables.Table`2.Insert(TEntity entity, Transaction transaction)
   at Effort.Internal.Common.DatabaseReflectionHelper.WrapperMethods.InsertEntity(ITable`1 table, TEntity entity, Transaction transaction)
 --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Effort.Internal.Common.DatabaseReflectionHelper.InsertEntity(ITable table, Object entity, Transaction transaction)
   at Effort.Internal.CommandActions.InsertCommandAction.CreateAndInsertEntity(ITable table, IList`1 memberBindings, Transaction transaction)
   at Effort.Internal.CommandActions.InsertCommandAction.ExecuteNonQuery(ActionContext context)
   at Effort.Provider.EffortEntityCommand.ExecuteNonQuery()
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
   at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
   at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
 --- End of inner exception stack trace ---
    at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult, Func`2 updateFunction)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
   at System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27()
   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
 --- End of inner exception stack trace ---
    at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
   at System.Data.Entity.Migrations.History.HistoryRepository.BootstrapUsingEFProviderDdl(VersionedModel versionedModel)
   at System.Data.Entity.Internal.InternalContext.<SaveMetadataToDatabase>b__7()
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
   at System.Data.Entity.Internal.InternalContext.SaveMetadataToDatabase()
   at System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext)
   at System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState)
   at System.Data.Entity.Database.Create(DatabaseExistenceState existenceState)
   at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)
   at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateInitializationAction>b__e()
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
 --- End of inner exception stack trace ---
    at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
   at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
   at System.Linq.Queryable.Count(IQueryable`1 source)

   at Model.MyProj... my test method call stack here

나는이 테스트에서 여러 DB 컨텍스트를 사용하며이 경우를 제외하고는 모두 작동합니다.

var query = db.MyEntities.Count(); // will throw the exception above ONLY FOR SOME DB CONTEXTS

실제로 Add 와 같은 컨텍스트에서의 모든 조작은 throw됩니다.

노력 웹 사이트 또는 검색으로 동일한 문제가있는 사람을 찾을 수 없습니다. 어쩌면 그것은 버그일까요? 최신 버전의 노력 - 1.1.4 및 Entity Framework - 6.1.3을 사용하고 있습니다.

나는 DbContext 또는 엔티티 클래스에 대한 특별한 것을 확인하고 아무것도 찾지 못했습니다.

인기 답변

이 문제가 있었고 각 컨텍스트마다 별도의 연결 ( Effort.DbConnectionFactory.CreatePersistent )을 사용하면 문제가 해결된다는 것을 Effort.DbConnectionFactory.CreatePersistent .

필자의 경우 각 컨텍스트는 완전히 다른 테이블에서 작동하므로 Effort / NMemory에서 충돌이 없어야합니다. 버그 보고서가 건전하다고 생각합니다. 그러나이 정보는 그 동안 사람들을 차단 해제 할 수 있습니다.

트레이드 오프는 이것이 동일한 테이블에서 실제로 작동하는 두 가지 컨텍스트를 가지고 있다고 경고 할 수 있다는 것입니다.이 컨텍스트는 나쁜 것이므로 너무주의해야합니다.



Related

아래 라이선스: CC-BY-SA with attribution
와 제휴하지 않음 Stack Overflow
이 KB는 합법적입니까? 예, 이유를 알아보십시오.
아래 라이선스: CC-BY-SA with attribution
와 제휴하지 않음 Stack Overflow
이 KB는 합법적입니까? 예, 이유를 알아보십시오.