Create example queries in Console project.
This commit is contained in:
parent
23a75282c1
commit
61b0e99f94
@ -1,2 +1,32 @@
|
|||||||
// See https://aka.ms/new-console-template for more information
|
using EntityFrameworkCore.Data;
|
||||||
Console.WriteLine("Hello, World!");
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user