add examples for ExecuteDelete and ExecuteUpdate functions.
This commit is contained in:
parent
86b2e60e8c
commit
10d207cb44
@ -13,6 +13,23 @@ using var context = new DeadBallZoneLeagueDbContext();
|
|||||||
// Rather than raise: "System.InvalidOperationException: Sequence contains no elements."
|
// Rather than raise: "System.InvalidOperationException: Sequence contains no elements."
|
||||||
// var firstCoach = await context.Coaches.FirstOrDefaultAsync();
|
// var firstCoach = await context.Coaches.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
async Task ExecuteDelete(string name)
|
||||||
|
{
|
||||||
|
// var coaches = await context.Coaches.Where(c => c.Name == name).ToListAsync();
|
||||||
|
// context.RemoveRange(coaches);
|
||||||
|
// await context.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Simplified:
|
||||||
|
await context.Coaches.Where(c => c.Name == name).ExecuteDeleteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ExecuteUpdate(int id)
|
||||||
|
{
|
||||||
|
await context.Coaches
|
||||||
|
.Where(c => c.Id == id)
|
||||||
|
.ExecuteUpdateAsync(set => set.SetProperty(c => c.CreatedDate, DateTime.UtcNow));
|
||||||
|
}
|
||||||
|
|
||||||
async Task DeleteCoach(int id)
|
async Task DeleteCoach(int id)
|
||||||
{
|
{
|
||||||
var coach = await context.Coaches.FindAsync(id);
|
var coach = await context.Coaches.FindAsync(id);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user