Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public long Stream_ODE() => _conn.Command(Sql).Map<Post>().Read(static items =>
public List<Post> QueryResult_Dapper() => _conn.Query<Post>(Sql).AsList();

[BenchmarkCategory("QueryResult"), Benchmark]
#pragma warning disable CS0618 // measures the deprecated Retrieve + DequeueAs route until 12
public List<Post> QueryResult_ODE() => _conn.Command(Sql).Retrieve().DequeueAs<Post>().ToList();
#pragma warning restore CS0618

[BenchmarkCategory("Dictionary"), Benchmark(Baseline = true)]
public Dictionary<int, Post> Dictionary_Dapper() => _conn.Query<Post>(Sql).ToDictionary(p => p.Id);
Expand Down
26 changes: 26 additions & 0 deletions Source/Core/Core/QueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ static ImmutableArray<T> Immute<T>(IEnumerable<T> source)
}

/// <summary>
/// Obsolete: nothing in the library returns this type; there is no replacement (rows come back as a <see cref="List{T}"/> from <see cref="MappedQuery{T}.ToList"/>).
/// A container for data reader results that also provides the column names and
/// other helpful data methods.
/// </summary>
/// <remarks>Obsolete in 11.0, removed in 12. See <see href="https://open-net-libraries.github.io/Open.Database.Extensions/articles/whats-new-11.html#deprecated-in-110">Deprecated in 11.0</see>.</remarks>
/// <typeparam name="T">The type of the items in the resultant enumerable.</typeparam>
/// <typeparam name="TResult">The type of the result property.</typeparam>
[Obsolete(QueryResultExtensions._queryResultCollectionObsolete)]
public class QueryResultCollection<T, TResult> : QueryResult<TResult>, IEnumerable<T>
where TResult : IEnumerable<T>
{
Expand Down Expand Up @@ -108,10 +111,13 @@ IEnumerator IEnumerable.GetEnumerator()
}

/// <summary>
/// Obsolete: nothing in the library returns this type; there is no replacement (rows come back as a <see cref="List{T}"/> from <see cref="MappedQuery{T}.ToList"/>).
/// A container for data reader results that also provides the column names and
/// other helpful data methods.
/// </summary>
/// <remarks>Obsolete in 11.0, removed in 12. See <see href="https://open-net-libraries.github.io/Open.Database.Extensions/articles/whats-new-11.html#deprecated-in-110">Deprecated in 11.0</see>.</remarks>
/// <typeparam name="T">The type of the items in the resultant enumerable.</typeparam>
[Obsolete(QueryResultExtensions._queryResultCollectionObsolete)]
public class QueryResultCollection<T> : QueryResultCollection<T, IEnumerable<T>>
{
/// <summary>Constructs a <see cref="QueryResultCollection{T}"/>.</summary>
Expand Down Expand Up @@ -176,6 +182,14 @@ public QueryResultQueue(
/// </summary>
public static class QueryResultExtensions
{
internal const string _queryResultCollectionObsolete = "Nothing in the library returns this type, and there is no replacement. Get rows as a List<T> from .Map<T>().ToList(), or keep your own class. Removed in 12.";
const string AsMappedDictionariesTail = " DequeueAsMappedDictionaries drains the queue as you enumerate it, so it can be read once; this method could be read again. Removed in 12.";
const string AsMappedDictionariesObsolete = "Nothing in the library returns the QueryResult<IEnumerable<object?[]>> this takes. To read rows as dictionaries use .Retrieve().DequeueAsMappedDictionaries(), or .Map(record => ...) with a selector that builds the dictionary." + AsMappedDictionariesTail;
const string AsMappedDictionariesAsyncObsolete = "Nothing in the library returns the QueryResult<IEnumerable<object?[]>> this takes. To read rows as dictionaries use (await cmd.RetrieveAsync()).DequeueAsMappedDictionaries(), or .Map(record => ...) with a selector that builds the dictionary." + AsMappedDictionariesTail;

const string DequeueAsTail = "Map reads in one pass instead of buffering raw rows first, reports a missing required column at the first row (so not for an empty result), and also reads later result sets: add .SingleResult() to read only the first, as Retrieve did. DequeueAs returned a one-pass enumerable; ToList() returns a List<T>. Removed in 12.";
const string DequeueAsObsolete = "Use cmd.Map<T>().ToList() instead of cmd.Retrieve().DequeueAs<T>(), or cmd.Map(map).ToList() when you passed a RowMap (DequeueAs accepted a null map; Map(map) throws on null). On an IDbCommand use command.Results<T>() (it takes no CommandBehavior); on an IDataReader use reader.ResultsBuffered<T>() (reader.Results<T>() is lazy). " + DequeueAsTail;
const string DequeueAsAsyncObsolete = "Use await cmd.Map<T>().ToListAsync() instead of (await cmd.RetrieveAsync()).DequeueAs<T>(), or cmd.Map(map).ToListAsync() when you passed a RowMap (DequeueAs accepted a null map; Map(map) throws on null). On a DbCommand use await command.ResultsAsync<T>(). " + DequeueAsTail;
/// <summary>
/// Returns an enumerable that dequeues the results and returns a column
/// mapped dictionary for each entry.<see cref="DBNull"/> values are converted to null.
Expand Down Expand Up @@ -217,9 +231,11 @@ public static class QueryResultExtensions
=> (await source.ConfigureAwait(false)).DequeueAsMappedDictionaries();

/// <summary>
/// Obsolete: use <see cref="CoreExtensions.Map{T}(IExecuteReader)"/> then <see cref="MappedQuery{T}.ToList"/> (async: <see cref="MappedQuery{T}.ToListAsync(CancellationToken)"/>).
/// Returns an enumerable that dequeues the results and attempts to map the
/// fields to type T.
/// </summary>
/// <remarks>Obsolete in 11.0, removed in 12. Replace the whole chain <c>cmd.Retrieve().DequeueAs&lt;T&gt;()</c>: on an <c>IExecuteReader</c> use <c>cmd.Map&lt;T&gt;().ToList()</c> (<c>cmd.Map(map).ToList()</c> with a <see cref="RowMap{T}"/>); on an <c>IDbCommand</c> use <c>Results&lt;T&gt;()</c>; on an <c>IDataReader</c> use <c>ResultsBuffered&lt;T&gt;()</c>; on a <c>DbCommand</c> async use <c>ResultsAsync&lt;T&gt;()</c>. See <see href="https://open-net-libraries.github.io/Open.Database.Extensions/articles/whats-new-11.html#deprecated-in-110">Deprecated in 11.0</see> for the differences and a before/after example.</remarks>
/// <remarks>Declare the <see cref="RowMap{T}"/> once and pass it: a map built in the call (a <c>new RowMap&lt;T&gt;(...)</c> or a collection expression in the argument) is rebuilt, and its row reader compiled, on every call.</remarks>
/// <remarks>DBNull values are converted to null.</remarks>
/// <param name="source">The query result. Typically produced by a
Expand All @@ -228,6 +244,7 @@ public static class QueryResultExtensions
/// <returns>An enumerable that dequeues the results and returns an entity
/// of type T.</returns>
/// <seealso cref="RowMap{T}"/>
[Obsolete(DequeueAsObsolete)]
public static IEnumerable<T> DequeueAs<T>(
this QueryResult<Queue<object[]>> source,
RowMap<T>? map = null)
Expand All @@ -242,6 +259,7 @@ public static IEnumerable<T> DequeueAs<T>(
/// <inheritdoc cref="DequeueAs{T}(QueryResult{Queue{object[]}}, RowMap{T}?)" />
/// <remarks>Declare the <see cref="RowMap{T}"/> once and pass it: a map built in the call (a <c>new RowMap&lt;T&gt;(...)</c> or a collection expression in the argument) is rebuilt, and its row reader compiled, on every call.</remarks>
/// <seealso cref="RowMap{T}"/>
[Obsolete(DequeueAsAsyncObsolete)]
public static async ValueTask<IEnumerable<T>> DequeueAs<T>(
this Task<QueryResult<Queue<object[]>>> source,
RowMap<T>? map = null)
Expand All @@ -256,6 +274,7 @@ public static async ValueTask<IEnumerable<T>> DequeueAs<T>(
/// <inheritdoc cref="DequeueAs{T}(QueryResult{Queue{object[]}}, RowMap{T}?)" />
/// <remarks>Declare the <see cref="RowMap{T}"/> once and pass it: a map built in the call (a <c>new RowMap&lt;T&gt;(...)</c> or a collection expression in the argument) is rebuilt, and its row reader compiled, on every call.</remarks>
/// <seealso cref="RowMap{T}"/>
[Obsolete(DequeueAsAsyncObsolete)]
public static async ValueTask<IEnumerable<T>> DequeueAs<T>(
this ValueTask<QueryResult<Queue<object[]>>> source,
RowMap<T>? map = null)
Expand All @@ -265,25 +284,30 @@ public static async ValueTask<IEnumerable<T>> DequeueAs<T>(
}

/// <inheritdoc cref="DequeueAs{T}(QueryResult{Queue{object[]}}, RowMap{T}?)" />
[Obsolete(DequeueAsAsyncObsolete)]
[OverloadResolutionPriority(1)]
public static ValueTask<IEnumerable<T>> DequeueAs<T>(
this Task<QueryResult<Queue<object[]>>> source)
=> DequeueAs<T>(source, null);

/// <inheritdoc cref="DequeueAs{T}(QueryResult{Queue{object[]}}, RowMap{T}?)" />
[Obsolete(DequeueAsAsyncObsolete)]
[OverloadResolutionPriority(1)]
public static ValueTask<IEnumerable<T>> DequeueAs<T>(
this ValueTask<QueryResult<Queue<object[]>>> source)
=> DequeueAs<T>(source, null);

/// <summary>
/// Obsolete: nothing produces the source this takes. Use <see cref="DequeueAsMappedDictionaries(QueryResult{Queue{object[]}})"/> on a <c>Retrieve()</c> result, or <see cref="CoreExtensions.Map{T}(IExecuteReader, Func{IDataRecord, T})"/> with your own selector.
/// Returns an enumerable that dequeues the results and returns a column
/// mapped dictionary for each entry.<see cref="DBNull"/> values are converted to null.
/// </summary>
/// <remarks>Obsolete in 11.0, removed in 12. See <see href="https://open-net-libraries.github.io/Open.Database.Extensions/articles/whats-new-11.html#deprecated-in-110">Deprecated in 11.0</see>.</remarks>
/// <param name="source">The query result. Typically produced by a
/// .Retrieve method.</param>
/// <returns>An enumerable that dequeues the results and returns a column
/// mapped dictionary for each entry</returns>
[Obsolete(AsMappedDictionariesObsolete)]
public static IEnumerable<Dictionary<string, object?>> AsMappedDictionaries(this QueryResult<IEnumerable<object?[]>> source)
{
return source is null
Expand All @@ -307,11 +331,13 @@ public static ValueTask<IEnumerable<T>> DequeueAs<T>(

/// <inheritdoc
/// cref="AsMappedDictionaries(QueryResult{IEnumerable{object?[]}})"/>
[Obsolete(AsMappedDictionariesAsyncObsolete)]
public static async ValueTask<IEnumerable<Dictionary<string, object?>>> AsMappedDictionaries(this ValueTask<QueryResult<IEnumerable<object?[]>>> source)
=> AsMappedDictionaries(await source.ConfigureAwait(false));

/// <inheritdoc
/// cref="AsMappedDictionaries(QueryResult{IEnumerable{object?[]}})"/>
[Obsolete(AsMappedDictionariesAsyncObsolete)]
public static async ValueTask<IEnumerable<Dictionary<string, object?>>> AsMappedDictionaries(this Task<QueryResult<IEnumerable<object?[]>>> source)
=> AsMappedDictionaries(await (source ?? throw new ArgumentNullException(nameof(source))).ConfigureAwait(false));
}
23 changes: 23 additions & 0 deletions Source/Core/ExpressiveDbCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public abstract partial class ExpressiveDbCommandBase<TConnection, TCommand, TRe
where TDbType : struct
where TThis : ExpressiveDbCommandBase<TConnection, TCommand, TReader, TDbType, TThis>
{
const string LaterSets = "Map also reads the later result sets, so a failure in one is thrown; add .SingleResult() to read only the first, as this method does.";
const string ResultsAsyncObsolete = "Use .Map<T>().ToListAsync() instead (.Map(map).ToListAsync() when you pass a RowMap; Map does not accept a null map; pass a CancellationToken to ToListAsync if you want one, it is optional and combines with the command's token). " + LaterSets + " Map returns a List<T>. Removed in 12.";
const string TakeAsyncObsolete = "Use .Map(selector).Take(count).ToListAsync(cancellationToken) instead. " + LaterSets + " It returns a List<T>, and Take(0) now runs the command; this method did not. Map has no CommandBehavior argument: if you passed one, use var list = new List<T>(); await cmd.IterateReaderWhileAsync(r => { list.Add(selector(r)); return list.Count < count; }, behavior). Removed in 12.";
const string ToListAsyncObsolete = "Use .Map(selector).ToListAsync(cancellationToken) instead. " + LaterSets + " Map has no CommandBehavior argument: if you passed one, use var list = new List<T>(); await cmd.IterateReaderAsync(r => list.Add(selector(r)), behavior). Removed in 12.";

/// <summary>Constructs a an expressive command.</summary>
/// <param name="connectionPool">The pool to acquire connections from.</param>
/// <param name="type">The command type.</param>
Expand Down Expand Up @@ -174,13 +179,20 @@ public async ValueTask<T> ExecuteScalarAsync<T>(Func<object?, ValueTask<T>> tran
}

/// <summary>
/// Obsolete: use <see cref="CoreExtensions.Map{T}(IExecuteReader, Func{IDataRecord, T})"/>, then <see cref="MappedQuery{T}.Take(int)"/>, then <see cref="MappedQueryWithTake{T}.ToListAsync(CancellationToken)"/>.
/// Asynchronously iterates a IDataReader and returns the each result until the count is met.
/// </summary>
/// <remarks>
/// Obsolete in 11.0, removed in 12. See <see href="https://open-net-libraries.github.io/Open.Database.Extensions/articles/whats-new-11.html#deprecated-in-110">Deprecated in 11.0</see>.
/// <c>Map</c> has no <see cref="CommandBehavior"/> argument: if you passed one, run the reader yourself with
/// <c>IterateReaderWhileAsync(record =&gt; { list.Add(selector(record)); return list.Count &lt; count; }, behavior)</c>.
/// </remarks>
/// <typeparam name="T">The return type of the transform function.</typeparam>
/// <param name="transform">The transform function to process each IDataRecord.</param>
/// <param name="count">The maximum number of records before complete.</param>
/// <param name="behavior">The behavior to use with the data reader.</param>
/// <returns>The value from the transform.</returns>
[Obsolete(TakeAsyncObsolete)]
public ValueTask<IList<T>> TakeAsync<T>(Func<IDataRecord, T> transform, int count, CommandBehavior behavior = CommandBehavior.Default)
{
if (transform is null) throw new ArgumentNullException(nameof(transform));
Expand Down Expand Up @@ -238,11 +250,18 @@ public ValueTask<QueryResultQueue<object[]>> RetrieveAsync(string c, params IEnu
=> RetrieveAsync(others.Prepend(c));

/// <summary>
/// Obsolete: use <see cref="CoreExtensions.Map{T}(IExecuteReader, Func{IDataRecord, T})"/> then <see cref="MappedQuery{T}.ToListAsync(CancellationToken)"/>.
/// Asynchronously returns all records via a transform function.
/// </summary>
/// <remarks>
/// Obsolete in 11.0, removed in 12. See <see href="https://open-net-libraries.github.io/Open.Database.Extensions/articles/whats-new-11.html#deprecated-in-110">Deprecated in 11.0</see>.
/// <c>Map</c> has no <see cref="CommandBehavior"/> argument: if you passed one, run the reader yourself with
/// <c>IterateReaderAsync(record =&gt; list.Add(selector(record)), behavior)</c>.
/// </remarks>
/// <param name="transform">The desired column names.</param>
/// <param name="behavior">The behavior to use with the data reader.</param>
/// <returns>A task containing the list of results.</returns>
[Obsolete(ToListAsyncObsolete)]
public async ValueTask<List<T>> ToListAsync<T>(Func<IDataRecord, T> transform, CommandBehavior behavior = CommandBehavior.Default)
{
var results = new List<T>();
Expand All @@ -251,13 +270,16 @@ public async ValueTask<List<T>> ToListAsync<T>(Func<IDataRecord, T> transform, C
}

/// <summary>
/// Obsolete: use <see cref="CoreExtensions.Map{T}(IExecuteReader)"/> then <see cref="MappedQuery{T}.ToListAsync(CancellationToken)"/>.
/// Asynchronously returns all records and iteratively attempts to map the fields to type T.
/// </summary>
/// <remarks>Obsolete in 11.0, removed in 12. See <see href="https://open-net-libraries.github.io/Open.Database.Extensions/articles/whats-new-11.html#deprecated-in-110">Deprecated in 11.0</see> for the difference and a before/after example.</remarks>
/// <remarks>Declare the <see cref="RowMap{T}"/> once and pass it: a map built in the call (a <c>new RowMap&lt;T&gt;(...)</c> or a collection expression in the argument) is rebuilt, and its row reader compiled, on every call.</remarks>
/// <typeparam name="T">The model type to map the values to (using reflection).</typeparam>
/// <param name="map">An optional prebuilt <see cref="RowMap{T}"/>; <see langword="null"/> reads by column name.</param>
/// <returns>A task containing the list of results.</returns>
/// <seealso cref="RowMap{T}"/>
[Obsolete(ResultsAsyncObsolete)]
public ValueTask<IEnumerable<T>> ResultsAsync<T>(RowMap<T>? map = null)
{
// An unmappable T fails here, before the command runs.
Expand All @@ -267,6 +289,7 @@ public ValueTask<IEnumerable<T>> ResultsAsync<T>(RowMap<T>? map = null)
}

/// <inheritdoc cref="ResultsAsync{T}(RowMap{T}?)"/>
[Obsolete(ResultsAsyncObsolete)]
public ValueTask<IEnumerable<T>> ResultsAsync<T>()
{
// An unmappable T fails here, before the command runs.
Expand Down
Loading