to simplify the thread. if you use FirstOrDefault() on an EF query, under the covers it will read all pending rows via NextResult() processing before the row is returned from FirstOrDefault(). If you want the first row only of an EF query and do not any extra rows returned, you use the .Take();
var author = dbContext.Authors.Where(_ => _.State == "UT")
.Take(1)
.FirstOrDefault();
this tells the sqlserver to only return 1 row.
EF has limited support for canceling a pending query. You need access to the DbCommand instance. you can create your own for example:
using (var cmd = dbContext.Authors.Where(_ => _.State == "UT").CreateDbCommand())
{
await cmd.Connection.OpenAsync();
using var reader = await cmd.ExecuteReaderAsync();
if (await reader.ReadAsync())
{
// process first row
var
}
// attempt to cancel query
cmd.Cancel();
}
if you need this low level, you are better off with dapper, where at least the reader can bind to a POCO object.