Add insert example.

This commit is contained in:
Kevin Matsubara 2025-04-05 23:06:01 +02:00
parent 5a2a82b413
commit 963378f2e9

View File

@ -13,7 +13,16 @@ using var context = new DeadBallZoneLeagueDbContext();
// Rather than raise: "System.InvalidOperationException: Sequence contains no elements."
// var firstCoach = await context.Coaches.FirstOrDefaultAsync();
async Task InsertCoach(string name)
{
var coach = new Coach { Name = name, CreatedDate = DateTime.UtcNow };
await context.Coaches.AddAsync(coach);
Console.WriteLine(context.ChangeTracker.DebugView.LongView);
await context.SaveChangesAsync();
// If you have a list, you can use a batch insert, instead of a loop:
// await context.Coaches.AddRangeAsync(coaches);
}
async Task ListVSIQueryableCall()
{