Method SingleOrDefaultAsync
| Improve this Doc View SourceSingleOrDefaultAsync<TEntity, T>(DbSet<TEntity>, Func<TEntity, T>, CancellationToken)
Returns the only value of specified database recordset column, or a default value if no record exists; this method throws an exception if more than one records exist.
Declaration
public static Task<T> SingleOrDefaultAsync<TEntity, T>(this DbSet<TEntity> dbSet, Func<TEntity, T> getColumn, CancellationToken ct = default(CancellationToken))
where TEntity : class, IEntity, new()
where T : Column, IColumn<DbReader>, new()
Parameters
Type | Name | Description |
---|---|---|
DbSet<TEntity> | dbSet | The database recordset. |
System.Func<TEntity, T> | getColumn | Delegate to return the column from Database recordset. |
System.Threading.CancellationToken | ct | The async cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | The only or default value. |
Type Parameters
Name | Description |
---|---|
TEntity | The entity type of database recordset. |
T | The data type of the column. |