From 963378f2e91ddafd4512559c28304b45b605a7ae Mon Sep 17 00:00:00 2001 From: Kevin Matsubara Date: Sat, 5 Apr 2025 23:06:01 +0200 Subject: [PATCH] Add insert example. --- EntityFrameworkCore.Console/Program.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/EntityFrameworkCore.Console/Program.cs b/EntityFrameworkCore.Console/Program.cs index 4adb7d3..35d691b 100644 --- a/EntityFrameworkCore.Console/Program.cs +++ b/EntityFrameworkCore.Console/Program.cs @@ -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() {