mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2025-12-06 05:32:03 +01:00
26 lines
696 B
C#
26 lines
696 B
C#
using Microsoft.EntityFrameworkCore; // for GenerateCreateScript()
|
|
using Packt.Shared; // Academy
|
|
|
|
using (Academy a = new())
|
|
{
|
|
bool deleted = await a.Database.EnsureDeletedAsync();
|
|
WriteLine($"Database deleted: {deleted}");
|
|
|
|
bool created = await a.Database.EnsureCreatedAsync();
|
|
WriteLine($"Database created: {created}");
|
|
|
|
WriteLine("SQL script used to create database:");
|
|
WriteLine(a.Database.GenerateCreateScript());
|
|
|
|
foreach (Student s in a.Students.Include(s => s.Courses))
|
|
{
|
|
WriteLine("{0} {1} attends the following {2} courses:",
|
|
s.FirstName, s.LastName, s.Courses.Count);
|
|
|
|
foreach (Course c in s.Courses)
|
|
{
|
|
WriteLine($" {c.Title}");
|
|
}
|
|
}
|
|
}
|