Hi support team,
Could you help me which part am I missing when I upgrade from .net version 8 to 9?
After I upgrade to .net version 9.0 I met this issue when running migration cmd like: "add-migration... or update-database"
Here is the err:
Could you help to give me the solution to resolve it? Thank you
9 Answer(s)
-
0
-
0
Hi EngincanV, Here is DbContextFactory file. Could you help me to check?
using System; using System.IO; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.Configuration; namespace Eduverse.EntityFrameworkCore; /* This class is needed for EF Core console commands * (like Add-Migration and Update-Database commands) */ public abstract class EduverseDbContextFactoryBase<TDbContext> : IDesignTimeDbContextFactory<TDbContext> where TDbContext : DbContext { public TDbContext CreateDbContext(string[] args) { // https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); var configuration = BuildConfiguration(); EduverseEfCoreEntityExtensionMappings.Configure(); var builder = new DbContextOptionsBuilder<TDbContext>() .UseNpgsql(configuration.GetConnectionString("Default")); return CreateDbContext(builder.Options); } protected abstract TDbContext CreateDbContext(DbContextOptions<TDbContext> dbContextOptions); protected IConfigurationRoot BuildConfiguration() { var builder = new ConfigurationBuilder() .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../Eduverse.DbMigrator/")) .AddJsonFile("appsettings.json", optional: false); return builder.Build(); } }
-
0
Hi EngincanV, Here is DbContextFactory file. Could you help me to check?
using System; using System.IO; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.Configuration; namespace Eduverse.EntityFrameworkCore; /* This class is needed for EF Core console commands * (like Add-Migration and Update-Database commands) */ public abstract class EduverseDbContextFactoryBase<TDbContext> : IDesignTimeDbContextFactory<TDbContext> where TDbContext : DbContext { public TDbContext CreateDbContext(string[] args) { // https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); var configuration = BuildConfiguration(); EduverseEfCoreEntityExtensionMappings.Configure(); var builder = new DbContextOptionsBuilder<TDbContext>() .UseNpgsql(configuration.GetConnectionString("Default")); return CreateDbContext(builder.Options); } protected abstract TDbContext CreateDbContext(DbContextOptions<TDbContext> dbContextOptions); protected IConfigurationRoot BuildConfiguration() { var builder = new ConfigurationBuilder() .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../Eduverse.DbMigrator/")) .AddJsonFile("appsettings.json", optional: false); return builder.Build(); } }
Hi again, can you make the following change and let me know if it fix your problem:
- .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../Eduverse.DbMigrator/")) + .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), @"..\Eduverse.DbMigrator\"))
-
0
Hi sir, it's still err like that. I don't know why if I using version 8 then it's ok. Could you give me another solution?
-
0
Hi sir, it's still err like that. I don't know why if I using version 8 then it's ok. Could you give me another solution?
Can you share your application via email to support@abp.io (with ticket number), so I can quickly check and fix the problem?
Regards.
-
0
Hi sir, Thank you for that but I can not share our application. For your information: I am using abp framework with .net version 9.0. we have 2 context 1 is XDbcontext 2 is XTenantDbContext. But I just met issue with XDbcontext and other I able to run migration. Eventhough, the XtenantDbContext using with the same DbcontextFactoryBase.
-
0
Hello
Can you please check this document Create a Second DbContext to create a second migration if it will helps you.
Thank you.
-
0
Hi, we already implemented 2 Dbcontext and it work fine. But when we upgrade to .net version 9.0 then it happen.
-
0
Hi, I already resolved this issue. The cause come from when I inject the Logger on DbContext then it's not able to create instance for that. Thank you all for your supporting me