Method SingleOrDefault
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
SingleOrDefault<T>(IDbCommand, Func<IDataRecord, T>, CommandBehavior)
Iterates an IDataReader and returns the first result through a transform function.
public static T? SingleOrDefault<T>(this IDbCommand command, Func<IDataRecord, T> transform, CommandBehavior behavior = CommandBehavior.Default)
Parameters
commandIDbCommandThe IDbCommand to generate a reader from.
transformFunc<IDataRecord, T>The transform function to process each IDataRecord.
behaviorCommandBehaviorThe behavior to use with the data reader.
Returns
- T
The value from the transform.
Type Parameters
TThe return type of the transform function.
Remarks
Returns default(T) if thre are no results.
Throws an InvalidOperationException if there is more than one result.