Move Id to BaseDomainModel and replace TeamId with regular Id.
This commit is contained in:
parent
10d207cb44
commit
ba3c65d7a1
@ -4,10 +4,10 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using var context = new DeadBallZoneLeagueDbContext();
|
||||
|
||||
// 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);
|
||||
// var teamOne = await context.Teams.FirstAsync(t => t.Id == 1);
|
||||
// var teamTwo = await context.Teams.FirstAsync(t => t.Id == 2);
|
||||
// var teamThree = await context.Teams.SingleAsync(t => t.Id == 3);
|
||||
// var teamFour = await context.Teams.SingleOrDefaultAsync(t => t.Id == 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."
|
||||
@ -86,7 +86,7 @@ async Task ListVSIQueryableCall()
|
||||
teamsAsList = await context.Teams.ToListAsync();
|
||||
if (option == 1)
|
||||
{
|
||||
teamsAsList = teamsAsList.Where(t => t.TeamId == 1).ToList();
|
||||
teamsAsList = teamsAsList.Where(t => t.Id == 1).ToList();
|
||||
}
|
||||
else if (option == 2)
|
||||
{
|
||||
@ -101,7 +101,7 @@ async Task ListVSIQueryableCall()
|
||||
var teamsAsQueryable = context.Teams.AsQueryable();
|
||||
if (option == 1)
|
||||
{
|
||||
teamsAsQueryable = teamsAsQueryable.Where(t => t.TeamId == 1);
|
||||
teamsAsQueryable = teamsAsQueryable.Where(t => t.Id == 1);
|
||||
}
|
||||
else if (option == 2)
|
||||
{
|
||||
@ -170,7 +170,7 @@ async Task GroupedTeams()
|
||||
foreach (var groupedTeam in groupedTeams)
|
||||
{
|
||||
Console.WriteLine(groupedTeam.Key);
|
||||
Console.WriteLine(groupedTeam.Sum(t => t.TeamId));
|
||||
Console.WriteLine(groupedTeam.Sum(t => t.Id));
|
||||
foreach (var team in groupedTeam)
|
||||
{
|
||||
Console.WriteLine(team.Name);
|
||||
@ -180,19 +180,19 @@ async Task GroupedTeams()
|
||||
|
||||
async Task CountFunctionsTeams(int id)
|
||||
{
|
||||
var numberOfTeams = await context.Teams.CountAsync(t => t.TeamId > id);
|
||||
var numberOfTeams = await context.Teams.CountAsync(t => t.Id > id);
|
||||
Console.WriteLine($"Number of teams with ID > {id}: {numberOfTeams}");
|
||||
|
||||
var maxTeams = await context.Teams.MaxAsync(t => t.TeamId);
|
||||
var maxTeams = await context.Teams.MaxAsync(t => t.Id);
|
||||
Console.WriteLine($"Max teams: {maxTeams}");
|
||||
|
||||
var minTeams = await context.Teams.MinAsync(t => t.TeamId);
|
||||
var minTeams = await context.Teams.MinAsync(t => t.Id);
|
||||
Console.WriteLine($"Min teams: {minTeams}");
|
||||
|
||||
var averageTeams = await context.Teams.AverageAsync(t => t.TeamId);
|
||||
var averageTeams = await context.Teams.AverageAsync(t => t.Id);
|
||||
Console.WriteLine($"Average teams: {averageTeams}");
|
||||
|
||||
var sumTeams = await context.Teams.SumAsync(t => t.TeamId);
|
||||
var sumTeams = await context.Teams.SumAsync(t => t.Id);
|
||||
Console.WriteLine($"Sum team IDs: {sumTeams}");
|
||||
}
|
||||
|
||||
|
||||
@ -31,21 +31,21 @@ public class DeadBallZoneLeagueDbContext : DbContext
|
||||
{
|
||||
modelBuilder.Entity<Team>().HasData(
|
||||
// Use hardcoded dates, not dynamic data such as new DateTimeOffset.UtcNow.DateTime for seeding.
|
||||
new Team { TeamId = 1, Name = "Neo Delhi", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33)},
|
||||
new Team { TeamId = 2, Name = "Voodoo", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 3, Name = "Penal X", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 4, Name = "Neo Tokyo", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 5, Name = "Neo Barcelona", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 6, Name = "Neo Manchester", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 7, Name = "Neo Bangkok", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 8, Name = "Neo Amsterdam", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 9, Name = "Killaklowns", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 10, Name = "Sol", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 11, Name = "DEC", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 12, Name = "Leopards", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 13, Name = "Harlequins", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 14, Name = "Gladiators", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { TeamId = 15, Name = "Fiz-O", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) }
|
||||
new Team { Id = 1, Name = "Neo Delhi", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33)},
|
||||
new Team { Id = 2, Name = "Voodoo", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 3, Name = "Penal X", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 4, Name = "Neo Tokyo", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 5, Name = "Neo Barcelona", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 6, Name = "Neo Manchester", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 7, Name = "Neo Bangkok", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 8, Name = "Neo Amsterdam", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 9, Name = "Killaklowns", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 10, Name = "Sol", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 11, Name = "DEC", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 12, Name = "Leopards", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 13, Name = "Harlequins", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 14, Name = "Gladiators", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) },
|
||||
new Team { Id = 15, Name = "Fiz-O", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33) }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,5 +2,6 @@
|
||||
// Since C#11, you do not need to wrap in accolades anymore.
|
||||
public abstract class BaseDomainModel
|
||||
{
|
||||
public int Id { get; set; } // Anything called "Id" is automatically a Primary Key.
|
||||
public DateTime CreatedDate { get; set;}
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
// Since C#11, you do not need to wrap in accolades anymore.
|
||||
public class Coach : BaseDomainModel
|
||||
{
|
||||
public int Id { get; set; } // Anything called "Id" is automatically a Primary Key.
|
||||
public string Name { get; set; } // Strings are automatically become VARCHAR database types.
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,5 @@
|
||||
// Since C#11, you do not need to wrap in accolades anymore.
|
||||
public class Team : BaseDomainModel
|
||||
{
|
||||
public int TeamId { get; set;} // This naming convention also allows EF to see this as a PK.
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user