Class ReaderExtensions
Extends Npgsql.NpgsqlDataReader with useful methods.
Namespace: Neon.Postgres
Assembly: Neon.Postgres.dll
Syntax
public static class ReaderExtensions
Methods
GetNullableBoolean(NpgsqlDataReader, int)
Returns the column value as a nullable boolean.
Declaration
public static bool? GetNullableBoolean(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| bool? | The nullable column value. |
GetNullableByte(NpgsqlDataReader, int)
Returns the column value as a nullable byte.
Declaration
public static byte? GetNullableByte(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| byte? | The nullable column value. |
GetNullableChar(NpgsqlDataReader, int)
Returns the column value as a nullable character.
Declaration
public static char? GetNullableChar(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| char? | The nullable column value. |
GetNullableDateTime(NpgsqlDataReader, int)
Returns the column value as a nullable DateTime.
Declaration
public static DateTime? GetNullableDateTime(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| Nullable | The nullable column value. |
GetNullableDecimal(NpgsqlDataReader, int)
Returns the column value as a nullable decimal.
Declaration
public static decimal? GetNullableDecimal(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| decimal? | The nullable column value. |
GetNullableDouble(NpgsqlDataReader, int)
Returns the column value as a nullable double.
Declaration
public static double? GetNullableDouble(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| double? | The nullable column value. |
GetNullableFloat(NpgsqlDataReader, int)
Returns the column value as a nullable float.
Declaration
public static float? GetNullableFloat(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| float? | The nullable column value. |
GetNullableGuid(NpgsqlDataReader, int)
Returns the column value as a nullable Guid.
Declaration
public static Guid? GetNullableGuid(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| Guid? | The nullable column value. |
GetNullableInt16(NpgsqlDataReader, int)
Returns the column value as a nullable short.
Declaration
public static short? GetNullableInt16(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| short? | The nullable column value. |
GetNullableInt32(NpgsqlDataReader, int)
Returns the column value as a nullable int.
Declaration
public static int? GetNullableInt32(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| int? | The nullable column value. |
GetNullableInt64(NpgsqlDataReader, int)
Returns the column value as a nullable long.
Declaration
public static long? GetNullableInt64(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| long? | The nullable column value. |
GetNullableString(NpgsqlDataReader, int)
Returns the column value as a string. Unlike GetStream(int),
this method can handle null column values.
Declaration
public static string GetNullableString(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| string | The column string or |
GetNullableTimeSpan(NpgsqlDataReader, int)
Returns the column value as a nullable TimeSpan.
Declaration
public static TimeSpan? GetNullableTimeSpan(this NpgsqlDataReader reader, int ordinal)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
| int | ordinal | The zero-based column position. |
Returns
| Type | Description |
|---|---|
| TimeSpan? | The nullable column value. |
ToAsyncEnumerable(NpgsqlDataReader)
Returns an enumerator suitable for enumerating database results asynchronously.
Declaration
public static ReaderAsyncEnumerator ToAsyncEnumerable(this NpgsqlDataReader reader)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
Returns
| Type | Description |
|---|---|
| ReaderAsyncEnumerator |
Remarks
This method provides a clean way to asynchronousl enumerate database results
using the C# await nforeach statement or the equivalent in of the .NET
languages. Here's an example:
using (var reader = await postgres.ExecuteReaderAsync("SELECT value FROM enumerate_table;"))
{
await foreach (var row in reader.ToAsyncEnumerable())
{
values.Add(row.GetInt32(0));
}
}
ToEnumerable(NpgsqlDataReader)
Returns an enumerator suitable for enumerating database results synchronously.
Declaration
public static ReaderEnumerator ToEnumerable(this NpgsqlDataReader reader)
Parameters
| Type | Name | Description |
|---|---|---|
| NpgsqlDataReader | reader | The data reader. |
Returns
| Type | Description |
|---|---|
| ReaderEnumerator | The ReaderEnumerator. |
Remarks
This method provides a clean way to enumerate database results using
the C# foreach statement or the equivalent in of the .NET languages.
Here's an example:
using (var reader = postgres.ExecuteReader("SELECT value FROM enumerate_table;"))
{
foreach (var row in reader.ToEnumerable())
{
values.Add(row.GetInt32(0));
}
}