diff --git a/EntityFrameworkCore.Console/Program.cs b/EntityFrameworkCore.Console/Program.cs index 3751555..fa20316 100644 --- a/EntityFrameworkCore.Console/Program.cs +++ b/EntityFrameworkCore.Console/Program.cs @@ -1,2 +1,32 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using EntityFrameworkCore.Data; +using Microsoft.EntityFrameworkCore; + +using var context = new DeadBallZoneLeagueDbContext(); + +//PrintTeams(); + +var teamOne = await context.Teams.FirstAsync(t => t.TeamId == 1); +var teamTwo = await context.Teams.FirstAsync(t => t.TeamId == 2); +var teamThree = await context.Teams.SingleAsync(t => t.TeamId == 3); +var teamFour = await context.Teams.SingleOrDefaultAsync(t => t.TeamId == 3); + +// There is no entry for coaches yet, this function will provide a null to coach. +// Rather than raise: "System.InvalidOperationException: Sequence contains no elements." +var coach = await context.Coaches.FirstOrDefaultAsync(); + +// Selection based on finding the Primary Key. +var teamBasedOnId = await context.Teams.FindAsync(5); +if (teamBasedOnId != null) +{ + Console.WriteLine(teamBasedOnId.Name); +} + +void PrintTeams() +{ + var teams = context.Teams.ToList(); + + foreach (var team in teams) + { + Console.WriteLine(team.Name); + } +}