Problem creating DbContext

Jan 12, 2015 at 11:32 AM
I'm trying to create the dbcontext as shown in the code first example, but i get the following exeption:

Could not load type 'System.Data.Entity.ModelConfiguration.Conventions.ForeignKeyIndexConvention' from assembly 'EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

When i remove the following line from OnModelCreating method:
modelBuilder.Conventions.AddBefore<ForeignKeyIndexConvention>(new ForeignKeyNamingConvention());

Then i get the following exception:
Message: Sequence contains no matching element
at System.Linq.Enumerable.Single[TSource](IEnumerable1 source, Func2 predicate)
at System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest, String name)
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(EdmProperty column, EntityType table, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration)
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.<>c__DisplayClass1.<Configure>b__0(Tuple2 pm)
at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable
1 ts, Action1 action)
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable
1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration)

Any advice on how to get this to work?
Jan 12, 2015 at 9:16 PM
It seems that you are using a database specific data type.

Check the following issue page for workaround:
Feb 25, 2015 at 9:07 PM
Edited Feb 25, 2015 at 9:08 PM
I had a similar error and it turned out that in the project where I had the DbContext I was using a newer version of Entity Framework (6.1.1) but the Unit Test project where I was using Effort as an in-memory database had an older version of Entity Framework (6.0.0 if I recall correctly) that was automatically installed when I installed Effort from NuGet. Installing the same version of Entity Framework from the project with the DbContext into the Unit Test project (6.1.1 in my case) solved the problem. Hope this helps!