Table of Contents

Method ToHashSet

Namespace
Open.Database.Extensions.Synchronous
Assembly
Open.Database.Extensions.Core.dll

ToHashSet<T>(MappedQuery<T>, IEqualityComparer<T>?)

Reads every mapped row into a new HashSet<T>.

public static HashSet<T> ToHashSet<T>(this MappedQuery<T> query, IEqualityComparer<T>? comparer = null)

Parameters

query MappedQuery<T>

The query to execute.

comparer IEqualityComparer<T>

The comparer for the rows, or null to use the default comparer.

Returns

HashSet<T>

A set of the distinct rows. Rows that compare equal to an earlier row are dropped.

Type Parameters

T

The type each row is mapped to.

Remarks

All rows are buffered in memory before the call returns.

Pooled memory: the rows are held in arrays rented from a pool and given back when the call, the buffer or the stream is done. By default that pool is ArrayPool<T>.Shared. To use your own, call .UsePool(pool, clearOnReturn: ...) after Map: the pool is yours, ODX rents from it and gives back to it, and never disposes it. The arrays it hands out may be longer than asked for: ODX uses the rows it wrote and clears only those. A pool that hands out a shorter array than asked for makes the read throw InvalidOperationException. Returning an array must not throw.

Clearing: rows that hold references (a class, a string, a struct that contains either) are always cleared before their array goes back, so a pooled array never keeps a row alive; nothing turns that off. Rows with no references (an int, a plain struct) go back as they are, unless asked: UsePool(pool, clearOnReturn: true) clears them, clearOnReturn: false keeps them as they are whatever the app-wide setting says, and a query that does not call UsePool follows the setting. The app-wide setting is the AppContext switch Open.Database.Extensions.ClearPooledArrays (off by default; read once, so set it before the first query). Set it in the application's project file with <RuntimeHostConfigurationOption Include="Open.Database.Extensions.ClearPooledArrays" Value="true" />, which puts it in runtimeconfig.json, or call AppContext.SetSwitch before the first query.

Exceptions

ArgumentNullException

query is null.

See Also
ToList()

ToHashSet<T>(MappedQueryWithSkip<T>, IEqualityComparer<T>?)

Reads every mapped row into a new HashSet<T>.

public static HashSet<T> ToHashSet<T>(this MappedQueryWithSkip<T> query, IEqualityComparer<T>? comparer = null)

Parameters

query MappedQueryWithSkip<T>

The query to execute.

comparer IEqualityComparer<T>

The comparer for the rows, or null to use the default comparer.

Returns

HashSet<T>

A set of the distinct rows. Rows that compare equal to an earlier row are dropped.

Type Parameters

T

The type each row is mapped to.

Remarks

All rows are buffered in memory before the call returns.

Pooled memory: the rows are held in arrays rented from a pool and given back when the call, the buffer or the stream is done. By default that pool is ArrayPool<T>.Shared. To use your own, call .UsePool(pool, clearOnReturn: ...) after Map: the pool is yours, ODX rents from it and gives back to it, and never disposes it. The arrays it hands out may be longer than asked for: ODX uses the rows it wrote and clears only those. A pool that hands out a shorter array than asked for makes the read throw InvalidOperationException. Returning an array must not throw.

Clearing: rows that hold references (a class, a string, a struct that contains either) are always cleared before their array goes back, so a pooled array never keeps a row alive; nothing turns that off. Rows with no references (an int, a plain struct) go back as they are, unless asked: UsePool(pool, clearOnReturn: true) clears them, clearOnReturn: false keeps them as they are whatever the app-wide setting says, and a query that does not call UsePool follows the setting. The app-wide setting is the AppContext switch Open.Database.Extensions.ClearPooledArrays (off by default; read once, so set it before the first query). Set it in the application's project file with <RuntimeHostConfigurationOption Include="Open.Database.Extensions.ClearPooledArrays" Value="true" />, which puts it in runtimeconfig.json, or call AppContext.SetSwitch before the first query.

Exceptions

ArgumentNullException

query is null.

See Also
ToList()

ToHashSet<T>(MappedQueryWithTake<T>, IEqualityComparer<T>?)

Reads every mapped row into a new HashSet<T>.

public static HashSet<T> ToHashSet<T>(this MappedQueryWithTake<T> query, IEqualityComparer<T>? comparer = null)

Parameters

query MappedQueryWithTake<T>

The query to execute.

comparer IEqualityComparer<T>

The comparer for the rows, or null to use the default comparer.

Returns

HashSet<T>

A set of the distinct rows. Rows that compare equal to an earlier row are dropped.

Type Parameters

T

The type each row is mapped to.

Remarks

All rows are buffered in memory before the call returns.

Pooled memory: the rows are held in arrays rented from a pool and given back when the call, the buffer or the stream is done. By default that pool is ArrayPool<T>.Shared. To use your own, call .UsePool(pool, clearOnReturn: ...) after Map: the pool is yours, ODX rents from it and gives back to it, and never disposes it. The arrays it hands out may be longer than asked for: ODX uses the rows it wrote and clears only those. A pool that hands out a shorter array than asked for makes the read throw InvalidOperationException. Returning an array must not throw.

Clearing: rows that hold references (a class, a string, a struct that contains either) are always cleared before their array goes back, so a pooled array never keeps a row alive; nothing turns that off. Rows with no references (an int, a plain struct) go back as they are, unless asked: UsePool(pool, clearOnReturn: true) clears them, clearOnReturn: false keeps them as they are whatever the app-wide setting says, and a query that does not call UsePool follows the setting. The app-wide setting is the AppContext switch Open.Database.Extensions.ClearPooledArrays (off by default; read once, so set it before the first query). Set it in the application's project file with <RuntimeHostConfigurationOption Include="Open.Database.Extensions.ClearPooledArrays" Value="true" />, which puts it in runtimeconfig.json, or call AppContext.SetSwitch before the first query.

Exceptions

ArgumentNullException

query is null.

See Also
ToList()

ToHashSet<T>(MappedCommand<T>, IEqualityComparer<T>?)

Reads every mapped row into a new HashSet<T>.

public static HashSet<T> ToHashSet<T>(this MappedCommand<T> query, IEqualityComparer<T>? comparer = null)

Parameters

query MappedCommand<T>

The query to execute.

comparer IEqualityComparer<T>

The comparer for the rows, or null to use the default comparer.

Returns

HashSet<T>

A set of the distinct rows. Rows that compare equal to an earlier row are dropped.

Type Parameters

T

The type each row is mapped to.

Remarks

All rows are buffered in memory before the call returns.

Pooled memory: the rows are held in arrays rented from a pool and given back when the call, the buffer or the stream is done. By default that pool is ArrayPool<T>.Shared. To use your own, call .UsePool(pool, clearOnReturn: ...) after Map: the pool is yours, ODX rents from it and gives back to it, and never disposes it. The arrays it hands out may be longer than asked for: ODX uses the rows it wrote and clears only those. A pool that hands out a shorter array than asked for makes the read throw InvalidOperationException. Returning an array must not throw.

Clearing: rows that hold references (a class, a string, a struct that contains either) are always cleared before their array goes back, so a pooled array never keeps a row alive; nothing turns that off. Rows with no references (an int, a plain struct) go back as they are, unless asked: UsePool(pool, clearOnReturn: true) clears them, clearOnReturn: false keeps them as they are whatever the app-wide setting says, and a query that does not call UsePool follows the setting. The app-wide setting is the AppContext switch Open.Database.Extensions.ClearPooledArrays (off by default; read once, so set it before the first query). Set it in the application's project file with <RuntimeHostConfigurationOption Include="Open.Database.Extensions.ClearPooledArrays" Value="true" />, which puts it in runtimeconfig.json, or call AppContext.SetSwitch before the first query.

Exceptions

ArgumentNullException

query is null.

See Also
ToList()