Entity Framework Core verify SaveChanges count
I can't think of another way of doing this - only the database knows how many rows have been affected. That said, your code has some problems.
You need to dispose of your transaction when you're done with it. This has 2 additional benefits:

You don't need to rollback manually
You don't need to worry about exceptions in SaveChanges (you haven't handled that at all at the moment).

Let's look at how that changes things:
public static int SaveChangesAndVerify(
    this DbContext context,
    int expectedChangeCount)
{
    using (var transaction = context.Database.BeginTransaction())
    {
        var actualChangeCount = context.SaveChanges();
        if (actualChangeCount == expectedChangeCount)
        {
            transaction.Commit();
            return actualChangeCount;
        }
        throw new DbUpdateException($&quot;Expected count {expectedChangeCount} did not match actual count {actualChangeCount} while saving the changes.&quot;);
    }
}