Method GetOptional
GetOptional(string, object?[]?)
Executes a read-only query and returns the first row, or null if there are no rows.
public Task<IQueryRow?> GetOptional(string sql, object?[]? parameters = null)
Parameters
Returns
GetOptional<T>(string, object?[]?, SqlMapper<T>)
Executes a read-only query and returns the first row mapped using mapper,
or default(T) if there are no rows.
Note that default(T) is not null for all types.
Map to a nullable type (e.g. row => (long?)row.GetLong("id")) to ensure you get null.
public Task<T?> GetOptional<T>(string sql, object?[]? parameters, SqlMapper<T> mapper)
Parameters
Returns
- Task<T>
Type Parameters
T
GetOptional<T>(string, object?[]?)
Executes a read-only query and returns the first row mapped using T.FromRow,
or default(T) if there are no rows.
Note that default(T) is not null if T is a value type.
public Task<T?> GetOptional<T>(string sql, object?[]? parameters = null) where T : IFromRow<T>
Parameters
Returns
- Task<T>
Type Parameters
T