I'm using Effort
, Effort.EF6
as my In-Memory database to test my Web API 2
application.
I'm using Autofac
for my DI resolve.
This is my code in Startup.cs
builder.Register(c =>
{
var dbConnectionFactory =
Effort.DbConnectionFactory.CreatePersistent(nameof(CvManagementDbContext));
return new CvManagementDbContext(dbConnectionFactory);
})
.As<DbContext>()
.SingleInstance();
And in my CvManagementDbContext.cs
:
public CvManagementDbContext(DbConnection connection)
: base(connection, true)
{
}
[UPDATE]
This is my package.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ApiMultipartFormDataFormatter" version="1.0.3" targetFramework="net452" />
<package id="Autofac" version="4.8.1" targetFramework="net46" />
<package id="Autofac.WebApi2" version="4.2.0" targetFramework="net46" />
<package id="AutoMapper" version="7.0.1" targetFramework="net46" />
<package id="AutoMapper.EF6" version="1.1.1" targetFramework="net46" />
<package id="DelegateDecompiler" version="0.24.0" targetFramework="net46" />
<package id="DelegateDecompiler.EntityFramework" version="0.24.0" targetFramework="net46" />
<package id="Effort" version="1.3.10" targetFramework="net46" />
<package id="Effort.EF6" version="1.3.10" targetFramework="net46" />
<package id="EntityFramework" version="6.2.0" targetFramework="net46" />
<package id="JWT" version="4.0.0" targetFramework="net46" />
<package id="Microsoft.AspNet.Cors" version="5.2.6" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi" version="5.2.6" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.6" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.6" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Cors" version="5.2.6" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.6" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.6" targetFramework="net46" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net46" />
<package id="Microsoft.Net.Compilers" version="2.9.0" targetFramework="net46" developmentDependency="true" />
<package id="Microsoft.Owin" version="4.0.0" targetFramework="net46" />
<package id="Microsoft.Owin.Host.SystemWeb" version="4.0.0" targetFramework="net46" />
<package id="Mono.Reflection" version="1.1.0.0" targetFramework="net46" />
<package id="Mono.Reflection.Core" version="1.1.1" targetFramework="net46" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net46" />
<package id="NMemory" version="2.0.4" targetFramework="net46" />
<package id="Owin" version="1.0" targetFramework="net46" />
<package id="ServiceStack.Common" version="5.4.0" targetFramework="net46" />
<package id="ServiceStack.Interfaces" version="5.4.0" targetFramework="net46" />
<package id="ServiceStack.Redis" version="5.4.0" targetFramework="net46" />
<package id="ServiceStack.Text" version="5.4.0" targetFramework="net46" />
<package id="System.Buffers" version="4.5.0" targetFramework="net46" />
<package id="System.Memory" version="4.5.1" targetFramework="net46" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.1" targetFramework="net46" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net46" />
</packages>
The configuration of Effort in Web.config
<entityFramework>
<interceptors>
<interceptor type="Cv_Management.Interceptor.GlobalDbCommandInterceptor, Cv_Management" />
</interceptors>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
<provider invariantName="Effort.Provider" type="Effort.Provider.EffortProviderServices,Effort" />
</providers>
</entityFramework>
When my application starts an exception thrown in the console, which is :
'The 'Instance' member of the Entity Framework provider type 'Effort.Provider.EffortProviderServices, Effort, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46696d54971e6d' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.'
What wrong am I doing ?
I think, I managed to reproduced your issue. You see Effort
and Effort.EF6
are mutually exclusive libraries, you only one of them. According to Effort github:
If you use Entity Framework 6...
- You will need the Effort.EF6 package
- Check the offical NuGet site
otherwise...
- You will need the Effort package
- Check the offical NuGet site
I got your error when I have reference to dll from Effort
package in my csproj file:
<Reference Include="Effort, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46696d54971e6d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Effort.1.3.10\lib\net45\Effort.dll</HintPath>
</Reference>
The error is gone when I have changed reference to dll from Effort.EF6
package:
<Reference Include="Effort, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a46696d54971e6d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Effort.EF6.1.3.10\lib\net45\Effort.dll</HintPath>
</Reference>
Check references in your csproj file, make sure, that you use dll from Effort.EF6
. And get rid of Effort
package. Hope it helps.