33 lines
961 B
C#
33 lines
961 B
C#
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);
|
|
}
|
|
}
|