Entityframeworkcore 8 is not backward compatible with Entityframeworkcore 5.0.17, getting compile time error
Hello Everyone,
I am tried to upgrade Entityframeworkcore from version 5.0.17 to Entityframeworkcore from version 8.0.1 but the code started giving me compile time error which is given below
public class DataContextSession
{
public static IDbContextFactory<DbContext> DbContextFactory { get; set; }
}
public class StremeServices : IStremeServices
{
private static readonly Lazy<IStremeServices> _instance = new(() => new StremeServices());
public static IStremeServices Instance => _instance.Value;
// DEBT - Review if this can be further simplified
public static IServiceProvider ServiceProvider { get; set; }
public IServiceProvider ServiceContainer => ServiceProvider;
public IConfiguration Configuration => (ServiceContainer?.GetService(typeof(IConfiguration)) as IConfiguration);
public IDbContextFactory<StremeDataModel> StremeDbContextFactory
{
get => ServiceContainer?.GetService(typeof(IDbContextFactory<StremeDataModel>))
as IDbContextFactory<StremeDataModel>;
}
public StremeDataModel CreateStremeDbContext()
{
return StremeDbContextFactory.CreateDbContext();
}
}
`StremeServices.ServiceProvider = builder.Services.BuildServiceProvider();
DataContextSession.DbContextFactory = (IDbContextFactory<StremeDataModel>)StremeServices
.ServiceProvider
.GetService(typeof(IDbContextFactory<StremeDataModel>));`
and the error is given below
Severity Code Description Project File Line Suppression State
Error CS0266 Cannot implicitly convert type 'Microsoft.EntityFrameworkCore.IDbContextFactory<StremeContext.Data.StremeDataModel>' to 'Microsoft.EntityFrameworkCore.IDbContextFactory<Microsoft.EntityFrameworkCore.DbContext>'. An explicit conversion exists (are you missing a cast?) StremeWebAPICore D:\Projects\CLI Streme\Source Future\StremeFuture\Streme\StremeWebAPICore\Program.cs 99 Active
It works fine with the previous version but I am not sure why Its not working in latest efcore version. May be there are some breaking changes so that would be great if anybody can help me resolve this issue.
Best Regards
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
@ajcvickers Sure, I have attached a link from where you can download the zip file. https://file.io/wVYSfbGuqdpf
In all projects I am using EF Core 5.0.17 version but when you will upgrade the version to 7.00 or then you will be able to see the compile time issue in program.cs file of Web API Core project.
Duplicate of #30096