Skip to the content.

The Query APIs allow multiple rows to be returned, which is fine - but if you only want a single row, there are scenario-specific APIs that allow for significant additional optimizations. The QueryFirst, QueryFirstOrDefault, QuerySingle and QuerySingleOrDefault work as you would expect, and compare directly to the corresponding LINQ First, FirstOrDefault, Single and SingleOrDefault methods.

Bad:

var order = conn.Query<Order>(sql, args).First();

Good:

var order = conn.QueryFirst<Order>(sql, args);