Esempio n. 1
0
        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();
                }
            }
        }
Esempio n. 2
0
 public BlogService(
     AspDotNetCoreDemoDatabaseContext dbContext)
 {
     this.dbContext = dbContext;
 }
Esempio n. 3
0
 public HomeController(AspDotNetCoreDemoDatabaseContext dbContext)
 {
     this.dbContext = dbContext;
 }