private void ConfigureDatabase() { var optionsBuilder = new DbContextOptionsBuilder <AspDotNetCoreDemoDatabaseContext>(); optionsBuilder.UseSqlite(databaseConnectionString); using (var dbContext = new AspDotNetCoreDemoDatabaseContext(optionsBuilder.Options)) { dbContext.Database.EnsureCreated(); if (!dbContext.Blogs.Any()) { dbContext.Blogs.AddRange(new Blog[] { new Blog { BlogId = 1, Title = "Blog 1", SubTitle = "Blog 1 subtitle" }, new Blog { BlogId = 2, Title = "Blog 2", SubTitle = "Blog 2 subtitle" }, new Blog { BlogId = 3, Title = "Blog 3", SubTitle = "Blog 3 subtitle" } }); dbContext.SaveChanges(); } } }
public BlogService( AspDotNetCoreDemoDatabaseContext dbContext) { this.dbContext = dbContext; }
public HomeController(AspDotNetCoreDemoDatabaseContext dbContext) { this.dbContext = dbContext; }