4,826 questions
No migrations were applied. The database is already up to date error for MySQL database with asp.net core boilerplate,
Olaitan Itunu Elijah
0
Reputation points
this is my startup
namespace Vale.fintech.Web.Startup
{
public class Startup
{
private readonly IWebHostEnvironment _hostingEnvironment;
public Startup(IWebHostEnvironment env)
{
_hostingEnvironment = env;
}
public IServiceProvider ConfigureServices(IServiceCollection services)
{
//Configure DbContext
services.AddAbpDbContext<FintechDbContext>(options =>
{
DbContextOptionsConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
});
services.AddScoped<IAccountService, AccountService>();
services.AddScoped<ICustomerService, CustomerService>();
services.AddScoped<ITransactionService, TransactionService>();
services.AddScoped<IAccountManager, AccountManager>();
services.AddScoped<ICustomerManager, CustomerManager>();
services.AddScoped<ITransactionManager, TransactionManager>();
services.AddMvc();
services.AddControllersWithViews(options =>
{
}).AddNewtonsoftJson();
services.AddControllers();
services.AddTransient<CustomersController>();
services.AddTransient<AccountsController>();
services.AddTransient<TransactionsController>();
services.AddAutoMapper(typeof(Startup));
MapperConfiguration config = new MapperConfiguration(configuration =>
{
configuration.CreateMap<Customer, CustomerDto>();
configuration.CreateMap<CustomerDto, Customer>();
configuration.CreateMap<Customer, CustomersDTO>();
configuration.CreateMap<CustomersDTO, Customer>();
configuration.CreateMap<Account, AccountDto>();
configuration.CreateMap<AccountDto, Account>();
configuration.CreateMap<Account, CreateAccountDTO>();
configuration.CreateMap<CreateAccountDTO, Account>();
configuration.CreateMap<Transaction, TransactionDTO>();
configuration.CreateMap<TransactionDTO, Transaction>();
});
IMapper mapper = config.CreateMapper();
services.AddSingleton(mapper);
//Configure Abp and Dependency Injection
return services.AddAbp<FintechWebModule>(options =>
{
//Configure Log4Net logging
options.IocManager.IocContainer.AddFacility<LoggingFacility>(
f => f.UseAbpLog4Net().WithConfig(
_hostingEnvironment.IsDevelopment()
? "log4net.config"
: "log4net.Production.config"
)
);
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
app.UseAbp(); //Initializes ABP framework.
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
My appsetting.
{
"ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=valefintechdb;Uid=root;Pwd=ipassword;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
my dbcontext.
public class FintechDbContext : AbpDbContext <FintechDbContext>
{
//Add DbSet properties for your entities...
public virtual DbSet<Customer> Customers { get; set; }
public virtual DbSet<Account> Accounts { get; set; }
public virtual DbSet<Transaction> Transactions { get; set; }
public FintechDbContext(DbContextOptions<FintechDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
/* Configure the model here */
modelBuilder.Entity<Customer>().ToTable("Customers");
modelBuilder.Entity<Account>().ToTable("Accounts");
modelBuilder.Entity<Transaction>().ToTable("Transactions");
}
}
}
My Configurer.
public static class DbContextOptionsConfigurer
{
public static void Configure(DbContextOptionsBuilder<FintechDbContext> builder, string connectionString)
{
var serverVersion = ServerVersion.AutoDetect(connectionString);
builder.UseMySql(connectionString, serverVersion);
}
public static void Configure(DbContextOptionsBuilder<FintechDbContext> builder, DbConnection connection)
{
var serverVersion = ServerVersion.AutoDetect(connection.ConnectionString);
builder.UseMySql(connection, serverVersion);
}
}
public static class DbContextOptionsConfigurer
{
public static void Configure(DbContextOptionsBuilder<FintechDbContext> builder, string connectionString)
{
var serverVersion = ServerVersion.AutoDetect(connectionString);
builder.UseMySql(connectionString, serverVersion);
}
public static void Configure(DbContextOptionsBuilder<FintechDbContext> builder, DbConnection connection)
{
var serverVersion = ServerVersion.AutoDetect(connection.ConnectionString);
builder.UseMySql(connection, serverVersion);
}
}
Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | ASP.NET | ASP.NET API
448 questions
Sign in to answer