Skip to content

Commit dc7c8dd

Browse files
authored
Remove Unspeakable Type Workaround (#1843)
dotnet/aspnetcore#47548 has now been fixed. Removing the workaround that was added for it.
1 parent 8d7808c commit dc7c8dd

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

src/BenchmarksApps/TodosApi/DataExtensions.cs

-15
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,6 @@ public static Task<NpgsqlDataReader> QueryAsync(this NpgsqlCommand command, Canc
144144
public static Task<NpgsqlDataReader> QueryAsync(this NpgsqlCommand command, CommandBehavior commandBehavior, CancellationToken cancellationToken = default)
145145
=> command.ExecuteReaderAsync(commandBehavior, cancellationToken);
146146

147-
public static Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> enumerable, CancellationToken cancellationToken)
148-
=> ToListAsync(enumerable, null, cancellationToken);
149-
150-
public static async Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> enumerable, int? initialCapacity = null, CancellationToken cancellationToken = default)
151-
{
152-
var list = initialCapacity.HasValue ? new List<T>(initialCapacity.Value) : new List<T>();
153-
154-
await foreach (var item in enumerable.WithCancellation(cancellationToken))
155-
{
156-
list.Add(item);
157-
}
158-
159-
return list;
160-
}
161-
162147
public static NpgsqlParameterCollection AddTyped<T>(this NpgsqlParameterCollection parameters, T? value)
163148
{
164149
parameters.Add(new NpgsqlParameter<T>

src/BenchmarksApps/TodosApi/TodoApi.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ public static RouteGroupBuilder MapTodoApi(this IEndpointRouteBuilder routes)
1313

1414
group.AddValidationFilter();
1515

16-
// BUG: Having to call ToListAsync() on query results until JSON support for unspeakable types (https://github.com/dotnet/aspnetcore/issues/47548) is resolved
17-
1816
group.MapGet("/", (NpgsqlDataSource db, CancellationToken ct) =>
19-
db.QueryAsync<Todo>("SELECT * FROM Todos", ct).ToListAsync(ct))
17+
db.QueryAsync<Todo>("SELECT * FROM Todos", ct))
2018
.WithName("GetAllTodos");
2119

2220
group.MapGet("/complete", (NpgsqlDataSource db, CancellationToken ct) =>
23-
db.QueryAsync<Todo>("SELECT * FROM Todos WHERE IsComplete = true", ct).ToListAsync(ct))
21+
db.QueryAsync<Todo>("SELECT * FROM Todos WHERE IsComplete = true", ct))
2422
.WithName("GetCompleteTodos");
2523

2624
group.MapGet("/incomplete", (NpgsqlDataSource db, CancellationToken ct) =>
27-
db.QueryAsync<Todo>("SELECT * FROM Todos WHERE IsComplete = false", ct).ToListAsync(ct))
25+
db.QueryAsync<Todo>("SELECT * FROM Todos WHERE IsComplete = false", ct))
2826
.WithName("GetIncompleteTodos");
2927

3028
group.MapGet("/{id:int}", async Task<Results<Ok<Todo>, NotFound>> (int id, NpgsqlDataSource db, CancellationToken ct) =>
@@ -104,7 +102,6 @@ await db.ExecuteAsync(
104102
}
105103

106104
[JsonSerializable(typeof(Todo))]
107-
[JsonSerializable(typeof(List<Todo>))]
108105
[JsonSerializable(typeof(IAsyncEnumerable<Todo>))]
109106
internal partial class TodoApiJsonSerializerContext : JsonSerializerContext
110107
{

0 commit comments

Comments
 (0)