An async method calls SaveChanges, which blocks on the database where SaveChangesAsync would not

tx0/csharp:save-changes-in-asyncrecommendedwarningperformance/iodepth fastperformance

What it finds

SaveChanges waits for the database round trip on the calling thread. In an async method that thread could serve other work meanwhile; await SaveChangesAsync() frees it.

From the rule's source, save_changes_in_async.rs.

Example from the rule's tests
using System.Threading.Tasks; class Orders{    private readonly Db db = new Db();     async Task Add()    {        await Task.Yield();        db.SaveChanges();tx0 reports: SaveChanges blocks inside an async method        await db.SaveChangesAsync();    }} class Db{    public int SaveChanges() => 0;     public Task<int> SaveChangesAsync() => Task.FromResult(0);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:save-changes-in-async" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:save-changes-in-async] reason="..."

tx0 explain tx0/csharp:save-changes-in-async shows the same in the terminal. Found a false positive? Report it.