up:: CSharp
If you need to delete a record from the SQL DB using EF7 and get optimized result like:
DELETE FROM [Users]
WHERE [Id] = @p0;
You can use this syntax:
app.MapPut("delete", async (Guid id)=>
{
await db.Users
.Where(u => u.Id == id)
.ExecuteDeleteAsync();
});
This method doesn't need SaveChangesAsync()
.
It is also possible to update multiple records without downloading them before:
UPDATE [Users]
SET [Generations] = @p0
WHERE [BirthDate] > @p1
app.MapPut("update", async (AppDbContext db)=>
{
await db.Users
.Where(u => u.BirthDate > new DateTime(1980, 12, 13))
.ExecuteUpdateAsync(
s => s.SetProperty(c => c.Generations => "Gen X")
);
});