[英].Net Core 3 preview 5 with Entity Framework for Postgresql
我正在尝试将我的核心2.2项目(在2.2上可以正常运行)迁移到3.0预览版。 我在迁移存储库(实体框架)时遇到问题。
我收到以下错误消息:
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Query.Pipeline.IEntityQueryableTranslatorFactory' while attempting to activate 'Microsoft.EntityFrameworkCore.Query.Pipeline.QueryCompilationContextFactory2'.
我有以下依赖项列表:
以下代码失败:
_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();
}
}
启动包含:
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(); });
}
提示我,我没有正确插入EF,因此DI不起作用。 任何想法如何解决这一问题?
升级.net core 3预览版6之后,我遇到了类似的问题。经过大量的研究,我发现了有关Postgresql中T版本不兼容的问题。
https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/903
下一个版本将得到修复..等待几天以发布预览版7
我设法通过降级到Microsoft.EntityFrameworkCore 3.0.0-preview5来解决此问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.