Use SingleOrDefaultAsync for stricter query constraints
Replaced FirstOrDefaultAsync with SingleOrDefaultAsync in BodyQueryBehavior.cs and HeaderQueryBehavior.cs to enforce that database queries return at most one result. This change ensures an exception is thrown if multiple results are found, making debugging and error handling more explicit.
This commit is contained in:
parent
6f5409f528
commit
6208f642be
@ -13,7 +13,7 @@ public class BodyQueryBehavior<TRecAction>(IRecDbContext dbContext) : IPipelineB
|
||||
if (action.BodyQuery is null)
|
||||
return await next(cancel);
|
||||
|
||||
var result = await dbContext.BodyQueryResults.FromSqlRaw(action.BodyQuery).FirstOrDefaultAsync(cancel);
|
||||
var result = await dbContext.BodyQueryResults.FromSqlRaw(action.BodyQuery).SingleOrDefaultAsync(cancel);
|
||||
action.Body = result?.RawBody;
|
||||
|
||||
return await next(cancel);
|
||||
|
||||
@ -15,7 +15,7 @@ public class HeaderQueryBehavior<TRecAction>(IRecDbContext dbContext, ILogger<He
|
||||
if (action.HeaderQuery is null)
|
||||
return await next(cancel);
|
||||
|
||||
var result = await dbContext.HeaderQueryResults.FromSqlRaw(action.HeaderQuery).FirstOrDefaultAsync(cancel);
|
||||
var result = await dbContext.HeaderQueryResults.FromSqlRaw(action.HeaderQuery).SingleOrDefaultAsync(cancel);
|
||||
|
||||
if(result?.RawHeader is null)
|
||||
return await next(cancel);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user