mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-07 07:14:02 +00:00
Initial commit
This commit is contained in:
parent
01d6ccf414
commit
dd097904c2
54 changed files with 37154 additions and 0 deletions
25
vscode/Chapter10/CoursesAndStudents/Program.cs
Normal file
25
vscode/Chapter10/CoursesAndStudents/Program.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue