Reputation: 813
I am trying to migrate my core 2.2 project (works fine at 2.2) to 3.0 preview. And I have problem migrating my repositories (Entity Framework).
I've got following error message:
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Query.Pipeline.IEntityQueryableTranslatorFactory' while attempting to activate 'Microsoft.EntityFrameworkCore.Query.Pipeline.QueryCompilationContextFactory2'.
I've got following list of dependencies:
Following code fails on:
_context.Some.Where(x => x.UserId == userId).ToListAsync();
=>
public class MyRepository
{
private readonly MyContext _context;
public MyRepository(MyContext context)
{
_context = context;
}
public Task<List<MyEntity>> GetByUserIdAsync(string userId)
{
return _context.Some.Where(x => x.UserId == userId).ToListAsync();
}
}
Startup contains:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddMvc().AddNewtonsoftJson();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped<MyRepository, MyRepository>();
services.AddEntityFrameworkNpgsql()
.AddDbContext<MyContext>()
.BuildServiceProvider();
services.Configure<PostgresDatabaseConfiguration>(
_config.GetSection(PostgresDatabaseConfiguration.ConfigName));
services.AddAutoMapper(Assembly.GetExecutingAssembly());
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseRouting();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
It seams to my, that I am plug in EF incorrectly, so DI do not work. Any ideas how to fix this?
Upvotes: 0
Views: 652
Reputation: 1867
After upgrading .net core 3 preview 6 i had similar issue..after lots of research of i got this issue regarding t version incompatibility in postgresql.
https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/903
it will be fix n next release ..wait for some days to release preview 7
Upvotes: 1
Reputation: 813
I've managed to fix this with downgrade to Microsoft.EntityFrameworkCore 3.0.0-preview5
Upvotes: 0