227 lines
6.0 KiB
C#
227 lines
6.0 KiB
C#
using HomeLibrary.Api.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace HomeLibrary.Api.Data
|
|
{
|
|
public class HomeLibraryDbContext : DbContext
|
|
{
|
|
public HomeLibraryDbContext(DbContextOptions<HomeLibraryDbContext> options):base(options)
|
|
{
|
|
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
int bookId = 1;
|
|
int authorId = 1;
|
|
|
|
// --- Authors
|
|
modelBuilder.Entity<Author>().HasData(new Author
|
|
{
|
|
Id = authorId,
|
|
Name = "Glen Cook"
|
|
});
|
|
authorId++;
|
|
|
|
modelBuilder.Entity<Author>().HasData(new Author
|
|
{
|
|
Id = authorId,
|
|
Name = "William Shakespeare"
|
|
});
|
|
authorId++;
|
|
|
|
modelBuilder.Entity<Author>().HasData(new Author
|
|
{
|
|
Id = authorId,
|
|
Name = "John Grisham"
|
|
});
|
|
authorId++;
|
|
|
|
modelBuilder.Entity<Author>().HasData(new Author
|
|
{
|
|
Id = authorId,
|
|
Name = "Douglas Adams"
|
|
});
|
|
authorId++;
|
|
|
|
modelBuilder.Entity<Author>().HasData(new Author
|
|
{
|
|
Id = authorId,
|
|
Name = "Piers Anthony"
|
|
});
|
|
authorId++;
|
|
|
|
modelBuilder.Entity<Author>().HasData(new Author
|
|
{
|
|
Id = authorId,
|
|
Name = "Kevin J. Anderson"
|
|
});
|
|
authorId++;
|
|
|
|
modelBuilder.Entity<Author>().HasData(new Author
|
|
{
|
|
Id = authorId,
|
|
Name = "Geoffrey Chaucer"
|
|
});
|
|
authorId++;
|
|
|
|
modelBuilder.Entity<Author>().HasData(new Author
|
|
{
|
|
Id = authorId,
|
|
Name = "L. M. Montgomery"
|
|
});
|
|
authorId++;
|
|
|
|
modelBuilder.Entity<Author>().HasData(new Author
|
|
{
|
|
Id = authorId,
|
|
Name = "Patricia Miles Martin"
|
|
});
|
|
authorId++;
|
|
|
|
// --- End of Authors
|
|
|
|
|
|
// --- Books
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 1,
|
|
Title = "Chronicles of The Black Company",
|
|
Series = "The Black Company",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 1,
|
|
Title = "Port of Shadows",
|
|
Series = "The Black Company",
|
|
BookNumber = 2
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 2,
|
|
Title = "The Complete Works of William Shakespeare",
|
|
Series = "None",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 3,
|
|
Title = "The Client",
|
|
Series = "None",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 3,
|
|
Title = "Sooley",
|
|
Series = "None",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 3,
|
|
Title = "Theodore Boone: The Accused",
|
|
Series = "Theodore Boone",
|
|
BookNumber = 3
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 4,
|
|
Title = "The Hitchhiker's Guide to the Galaxy",
|
|
Series = "None",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 5,
|
|
Title = "Golem in the Gears",
|
|
Series = "Xanth",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 5,
|
|
Title = "Demons Don't Dream",
|
|
Series = "Xanth",
|
|
BookNumber = 2
|
|
});
|
|
bookId++;
|
|
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 6,
|
|
Title = "Tales of the Bounty Hunters",
|
|
Series = "Star Wars",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 7,
|
|
Title = "Canterbury Tales",
|
|
Series = "None",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 8,
|
|
Title = "Anne of Green Gables",
|
|
Series = "None",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
modelBuilder.Entity<Book>().HasData(new Book
|
|
{
|
|
Id = bookId,
|
|
AuthorId = 9,
|
|
Title = "Trina",
|
|
Series = "None",
|
|
BookNumber = 1
|
|
});
|
|
bookId++;
|
|
|
|
|
|
// --- End of Books
|
|
}
|
|
|
|
public DbSet<Book> Books { get; set; }
|
|
public DbSet<Author> Authors { get; set; }
|
|
}
|
|
}
|