Last active
September 7, 2019 17:50
-
-
Save Taifunov/7db7c19f86e20eca43608605210dd9e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class MyContext : DbContext | |
{ | |
public DbSet<PostData> Posts { get; set; } | |
public DbSet<VoteData> Votes { get; set; } | |
public MyContext(DbContextOptions<MyContext> options) : base(options) | |
{ | |
} | |
public MyContext() | |
{ | |
} | |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |
{ | |
if (!optionsBuilder.IsConfigured) | |
{ | |
optionsBuilder.UseSqlite("Data Source = DataDb.db;"); | |
} | |
} | |
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
modelBuilder.ApplyConfigurationsFromAssembly(typeof(MyContext).Assembly); | |
} | |
public class ContextBaseFactory : IDesignTimeDbContextFactory<MyContext> | |
{ | |
public MyContext CreateDbContext(string[] args) | |
{ | |
var optionsBuilder = new DbContextOptionsBuilder<MyContext>(); | |
if (!optionsBuilder.IsConfigured) | |
{ | |
optionsBuilder.UseSqlite("Data Source = DataDb.db;"); | |
} | |
return new MyContext(optionsBuilder.Options); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment