KeyNotFoundException EF6

Dec 2, 2013 at 7:09 AM
Hi, i've created my first test with effort. I want to add my data with normal DbSet using and I'm not sure what's wrong or if it is supported. This is my code:
        public void TestIndex()
            DbConnection connection = Effort.DbConnectionFactory.CreateTransient();
            CourseContext context = new CourseContext(connection);

            Course course = new Course();
            course.Id = 1;
            course.Name = "Test";

            var controller = new Controllers.CourseController(context);
            var result = controller.Details(1, "") as ViewResult;
            Assert.AreEqual("Details", result.ViewName);
and this is sthe error message I get: (at the Add-Part of my code)
Test Name:  TestIndex
Test FullName:  Coursika.Tests.CourseControllerTest.TestIndex
Test Source:    c:\repository\coursika\Coursika.Tests\CourseControllerTest.cs : line 19
Test Outcome:   Failed
Test Duration:  0:00:00,817088

Result Message: 
Test method Coursika.Tests.CourseControllerTest.TestIndex threw exception: 
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
Result StackTrace:  
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, StorageEntitySetMapping entitySetMapping, StorageMappingFragment 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.LazyInternalContext.MarkDatabaseInitialized()
   at System.Data.Entity.Database.Initialize(Boolean force)
   at Coursika.Tests.CourseControllerTest.TestIndex() in c:\repository\coursika\Coursika.Tests\CourseControllerTest.cs:line 22
And ideas?
Dec 2, 2013 at 8:33 AM
Edited Dec 2, 2013 at 8:38 AM

Check the comment section of this page:

Let me know if it solved your problem.
Dec 3, 2013 at 3:47 PM
Edited Dec 3, 2013 at 3:50 PM
Thanks, but I did not understand what to do. Nevertheless I ended up linking my project to the source of effort and now I have some more information. The Error is in method EffortProviderManifest.cs:97 where the following line is: PrimitiveType storeType = this.StoreTypeNameToStorePrimitiveType[name];
In this case the name is geography. Seems like there is an issue with that type?

Dec 3, 2013 at 4:23 PM
Hi, it's me again. I had a look into EntityFramework.SqlServer and found the System.Data.Resources.SqlClient.SqlProviderServices.ProviderManifest.xml which is used there. Then i copied the party that looked interesting to the EffortProviderManifest.xml (see below) and the error was gone. I do not know what I did here, but maybe it helps to close the issue?
 <Type Name="geography" PrimitiveTypeKind="Geography">
        <SRID Minimum="0" Maximum="9999" DefaultValue="Variable" Constant="false" />
        <IsStrict DefaultValue="true" Constant="false" />
    <Type Name="geometry" PrimitiveTypeKind="Geometry">
        <SRID Minimum="0" Maximum="9999" DefaultValue="Variable" Constant="false" />
        <IsStrict DefaultValue="true" Constant="false" />
Dec 4, 2013 at 8:58 PM
I edited my response, but somehow it was not replaced. I suggested to check the workaround referenced by the issue page.

However, it turned out that your issue is related to the lack of spatial type support. Adding these xml elements may help to avoid this exception, but it definitely need more digging to add this feature properly. It is already in my TODO list, but unfortunately I currently lack enough free time.
Marked as answer by AndiRudi on 12/6/2013 at 8:09 AM
Feb 2, 2015 at 2:48 PM
I am using the stable version Effort 1.0.0, dated Jun 9, 2014, and I also get this Exception, most probably as I am using spatial types.
What is the status on this? Are there any beta versions avaliable having support for spatial types?
If not, are there any future plans for this?
Feb 13, 2015 at 4:02 PM

There is no existing support (not even beta) and I am not planning to start work on this feature anytime soon.