Single doesn't limit number of results on query

Hello, I noticed that ServiceStack.OrmLite.OrmLiteReadExpressionsApiAsync.SingleAsync< T >(this IDbConnection dbConn, ISqlExpression expression, CancellationToken token = default) and ServiceStack.OrmLite.OrmLiteReadExpressionsApi.Single< T >(this IDbConnection dbConn, ISqlExpression expression) don’t limit the number of results returned from the query on provided SqlExpression. (ServiceStack 8.2.2)

I think it would make sense to limit the number of results to 1 (with TOP 1 in SqlServer) as the rest of the results are discarded anyway.
Kind regards,
Tomaž Petek

Single just returns a single record, like if you search by Primary Key, it doesn’t alter your query.
If you want it to limit it to 1result add it to your query expression, e.g:

var row = db.Single(db.From<Table>().Take(1));

I can understand not wanting to change the query that is provided but it its inconsistent.

// Adds take 1 automatically

// Doesn't add take 1
1 Like

Yeah it was weird that it was only being applied for 1 query, I’ve removed it in this commit to be consistent.

1 Like