Effort (EF6) exception when accessing DbSet (this key was not in the dictionary)

This is a little difficult to trace, but when using Effort to test Entity Framework 6, it seems to me that when trying to access one of them, a KeyNotFoundException error ("this key was not present in the dictionary") of DBSet repositories.

I noticed that it works with one or two DbSets in a DbContext, but as soon as I start adding several DbSets to a DbContext, I get the above error.

Code example (this is a simplification of the whole code, the error seems random when I comment on some DbSets from DbContext and then return them back. I also have partial classes for models, but sometimes it works, it seems strange):

Test

[Fact] public void MyTest() { var connection = Effort.DbConnectionFactory.CreateTransient(); var context = new StubDbContext(connection); var count = context.Models1.Count(); Assert.Equal(count, 0); } 

DBContext and DbSets Models

  public class StubEntityModelA { [Key] public int Id { get; set; } public string Name { get; set; } } public class StubEntityModelB { [Key] public int Id { get; set; } public string Name { get; set; } } public class StubEntityModelC { [Key] public int Id { get; set; } public string Name { get; set; } } public class StubDbContext : DbContext { public StubDbContext(DbConnection connection): base(connection, true) { } public virtual DbSet<StubEntityModelA> Models1 { get; set; } public virtual DbSet<StubEntityModelB> Models2 { get; set; } public virtual DbSet<StubEntityModelC> Models3 { get; set; } } 

Stack trace:

  at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Effort.Provider.EffortProviderManifest.GetStoreType(TypeUsage edmType) at System.Data.Entity.ModelConfiguration.Edm.Services.StructuralTypeMappingGenerator.MapTableColumn(EdmProperty property, String columnName, Boolean isInstancePropertyOnDerivedType) at System.Data.Entity.ModelConfiguration.Edm.Services.PropertyMappingGenerator.Generate(EntityType entityType, IEnumerable`1 properties, EntitySetMapping entitySetMapping, MappingFragment entityTypeMappingFragment, IList`1 propertyPath, Boolean createNewColumn) at System.Data.Entity.ModelConfiguration.Edm.Services.TableMappingGenerator.Generate(EntityType entityType, DbDatabaseMapping databaseMapping) at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.GenerateEntityTypes(DbDatabaseMapping databaseMapping) at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.Generate(EdmModel conceptualModel) at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 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[TSource](IQueryable`1 source) at XXXX.Business.Test.XXXXTests.IXXXXXXMethod.ShouldInsertRecordWhenNoneAlreadyExist() in C:\Workspaces\XXX\XXXXX\XXXXX.Business.Test\XXXXXXTests.cs:line 125 
+5
source share
2 answers

I have an exact problem. It turned out that this is because I used the SQL geography data type in some tables of the SQL 2014 database, and the effort does not support this data type , and there are currently no plans to add support for it, which leaves me in real quandry, since I cannot Find another in-memory database provider for EF6 that does!

There could potentially be other new types of reference types, which it also does not support, but is not sure.

+1
source

I have exactly the same stack trace, but the problem for me was related to the inheritance of the TPT Entity Framework. If you use it too, look at my answer here .

0
source

Source: https://habr.com/ru/post/1237372/


All Articles