restructured filetree
This commit is contained in:
committed by
Chris
parent
dcbed24638
commit
b837e1aad2
17
Data/ApplicationDbContext.cs
Normal file
17
Data/ApplicationDbContext.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Example.Models;
|
||||
|
||||
namespace Example.Data;
|
||||
|
||||
public class ApplicationDbContext : IdentityDbContext
|
||||
{
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Author> Authors => Set<Author>();
|
||||
public DbSet<Book> Books => Set<Book>();
|
||||
public DbSet<Review> Reviews => Set<Review>();
|
||||
}
|
||||
30
Data/ApplicationDbInitializer.cs
Normal file
30
Data/ApplicationDbInitializer.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Example.Models;
|
||||
|
||||
namespace Example.Data
|
||||
{
|
||||
public static class ApplicationDbInitializer
|
||||
{
|
||||
public static void Initialize(ApplicationDbContext db)
|
||||
{
|
||||
// Delete the database before we initialize it. This is common to do during development.
|
||||
db.Database.EnsureDeleted();
|
||||
|
||||
// Recreate the database and tables according to our models
|
||||
db.Database.EnsureCreated();
|
||||
|
||||
// Add test data to simplify debugging and testing
|
||||
|
||||
var authors = new[]
|
||||
{
|
||||
new Author("Author 1", "Author 1", new DateTime(1981, 1, 1)),
|
||||
new Author("Author 2", "Author 2", new DateTime(1982, 2, 2)),
|
||||
new Author("Author 3", "Author 3", new DateTime(1983, 3, 3))
|
||||
};
|
||||
|
||||
db.Authors.AddRange(authors);
|
||||
|
||||
// Finally save the added relationships
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user