Я купил книгу ASP. NET CORE 3 и Angular 9, третье издание, и сейчас читаю ее и пишу код. Однако у меня есть проблема, когда я запускаю приложение (нажимая клавишу F5 в Visual Studio 2019), каждый запрос к серверу выполняется очень медленно (иногда это может занять 25 секунд, а объем данных не так уж велик, 225 стран, и я выбираю их 10 на 10) и не знаю почему.
Я не знаю точно, какой файл я должен показать вам, ребята, поэтому, если у вас есть какие-либо идеи или вы хотите узнать какие-либо файлы, пожалуйста, сообщите мне в комментариях.
У меня есть это сообщение в консоли:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
---> System.ComponentModel.Win32Exception (258): Dépassement du délai d'attente.
at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__164_0(Task`1 result)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at WorldCities.Data.ApiResult`1.CreateAsync(IQueryable`1 source, Int32 pageIndex, Int32 pageSize, String sortColumn, String sortOrder, String filterColumn, String filterQuery) in E:\Software development\Portfolio\Projects\WorldCities\Data\ApiResult.cs:line 78
at WorldCities.Controllers.CitiesController.GetCities(Int32 pageIndex, Int32 pageSize, String sortColumn, String sortOrder, String filterColumn, String filterQuery) in E:\Software development\Portfolio\Projects\WorldCities\Controllers\CitiesController.cs:line 33
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
ClientConnectionId:e2d0fb93-033c-4ec3-8275-ef4ce243b670
Error Number:-2,State:0,Class:11
вот запрос:
public async Task<ActionResult<ApiResult<City>>> GetCities(
int pageIndex = 0,
int pageSize = 10,
string sortColumn = null,
string sortOrder = null,
string filterColumn = null,
string filterQuery = null)
{
return await ApiResult<City>
.CreateAsync(
_context.Cities,
pageIndex,
pageSize,
sortColumn,
sortOrder,
filterColumn,
filterQuery);
}
/// <summary>
/// Pages, sorts and/or filters a IQueryable source.
/// </summary>
/// <param name="source">An IQueryable source of generic type</param>
/// <param name="pageIndex">Zero-based current page index (0 = first page)</param>
/// <param name="pageSize">The actual size of each page</param>
/// <param name="sortColumn">The sorting colum name</param>
/// <param name="sortOrder">The sorting order ("ASC" or "DESC")</param>
/// <param name="filterColumn">The filtering column name</param>
/// <param name="filterQuery">The filtering query (value to lookup)</param>
/// <returns>
/// A object containing the IQueryable paged/sorted/filtered result
/// and all the relevant paging/sorting/filtering navigation info.
/// </returns>
public static async Task<ApiResult<T>> CreateAsync(
IQueryable<T> source,
int pageIndex,
int pageSize,
string sortColumn = null,
string sortOrder = null,
string filterColumn = null,
string filterQuery = null)
{
if (!String.IsNullOrEmpty(filterColumn) && !String.IsNullOrEmpty(filterQuery) && IsValidProperty(filterColumn))
{
source = source.Where(String.Format("{0}.Contains(@0)", filterColumn), filterQuery);
}
var count = await source.CountAsync();
if (!string.IsNullOrEmpty(sortColumn) && IsValidProperty(sortColumn))
{
sortOrder = !String.IsNullOrEmpty(sortOrder) && sortOrder.ToUpper() == "ASC" ? "ASC" : "DESC";
source = source.OrderBy(string.Format("{0} {1}", sortColumn, sortOrder));
}
source = source.Skip(pageIndex * pageSize).Take(pageSize);
var data = await source.ToListAsync();
return new ApiResult<T>(data, count, pageIndex, pageSize, sortColumn, sortOrder, filterColumn, filterQuery);
}
Когда я ввожу URL, чтобы получить данные непосредственно в моем веб-браузере, я сразу получаю результат .
Большое спасибо.