تخطَّ إلى المحتوى

Bulk operation (ARCH210)

هذا المحتوى غير متوفر بلغتك بعد.

Key dotnet.ef.bulk-operation · Severity info · Category ef

Loading and modifying many rows one by one is far slower than ExecuteUpdate/ExecuteDelete, which run in a single SQL command.

var expired = await _db.Tokens
.Where(t => t.ExpiresAt < now)
.ToListAsync();
_db.Tokens.RemoveRange(expired);
await _db.SaveChangesAsync();
await _db.Tokens
.Where(t => t.ExpiresAt < now)
.ExecuteDeleteAsync();

Use ExecuteUpdateAsync or ExecuteDeleteAsync for bulk update/delete.