I impliment clean architecture and i dont want to refrence my dataLayer to HostLayer and use HostDbContext(DesignTimeDbContext) for migration Only and my DataDbContext for connect to database like as abp FrameWork.
this is my dataLayer dbContext
namespace EntityCore.Data
{
public class MainApplicationDbContext : DbContext
{
public MainApplicationDbContext(DbContextOptions<MainApplicationDbContext> options)
: base(options)
{
}
public DbSet<Movie> Movies { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Movie>(b =>
{
b.ToTable("MoviesDBO");
b.HasIndex(t => t.Id);
b.Property(t => t.Name).IsRequired();
});
}
}
}
and this one is my HostDbContext
namespace MoviesHost.efCore
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
}
and this one is DesignTimeDbContext config
namespace MoviesHost.efCore
{
public class ApplicationContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
public ApplicationDbContext CreateDbContext(string[] args)
{
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseSqlServer(configuration.GetConnectionString("DefaultConnection"));
return new ApplicationDbContext(builder.Options);
}
private static IConfigurationRoot BuildConfiguration()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
return builder.Build();
}
}
}
but when i addMigration file is epmty as blow
namespace MoviesHost.Migrations
{
/// <inheritdoc />
public partial class initDatabase : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
ali Payande is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.