Hi
Am trying to create a database from existing migration persistence database
public CMSDBContext(DbContextOptions<CMSDBContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("dbo");
base.OnModelCreating(modelBuilder);
CustomDateConverter.DateToUTC(modelBuilder);
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
DateTime currentDateTime = DateTime.UtcNow;
foreach (var auditableEntity in ChangeTracker.Entries<IAuditable>())
{
if (auditableEntity.State == EntityState.Added || auditableEntity.State == EntityState.Modified)
{
switch (auditableEntity.State)
{
case EntityState.Added:
auditableEntity.Entity.CreatedAt = currentDateTime;
break;
case EntityState.Modified:
auditableEntity.Entity.UpdatedAt = currentDateTime;
break;
}
}
}
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
//Registering Services
public static IServiceCollection AddPresistenceInfrastructure(this IServiceCollection services)
{
services.AddDbContext<CMSDBContext>(options => options.UseSqlServer(SettingManager.CMSConnectionString));
#region Repositories
services.AddTransient(typeof(IGenericRepository<>), typeof(GenericRepository<>));
services.AddTransient(typeof(IReadonlyRepository<>), typeof(ReadonlyRepository<>));
services.AddTransient(typeof(ISectionRepository), typeof(SectionRepository));
#endregion
#region Cache
var redisConfigSection = SettingManager.GetSection(RedisSettings.SectionName);
services.AddSingleton<IConnectionMultiplexer>(sp => ConnectionMultiplexer.Connect(new ConfigurationOptions
{
EndPoints = { $"{redisConfigSection["Server"]}:{redisConfigSection["Port"]}" },
AllowAdmin = true,
AbortOnConnectFail = false,
}));
services.AddSingleton<ICacheService, RedisCacheService>();
#endregion
return services;
}
}
appsettings.json
"CMSConnection": "Server=Sandy-NB\\LOCALSERVER;Database=cms_db;User Id=sa;Password=xxxx;"
there are multiple migration files and no seed
What I have tried:
I got these error
PM> Update-database --verbose
Build started...
Build succeeded.
Unable to create an object of type 'CMSDBContext'. For the different patterns supported at design time, see https:
There were solutions about making the project as startup project (already done and no success)
I tried to initially create an empty database with the database name and tried again -- no success
Pretty sure that the code has no issues because it was working previously on other machines but what would be the possible issue causing this problem?