У меня проблема с выполнением View Component в моем веб-приложении .net Core.Я использовал его пару раз без проблем, но на этот раз он ведет себя немного забавно.
В окне вывода я отчетливо вижу, что Visual Studio пытается запрашивать данные из базы данных, но эта команда выполняется бесконечное количество элементов один за другим много раз в секунду, пока я не остановлю приложение (результатыконечно не рендер).
Также я заметил, что через некоторое время используемая память составляет около 2,5 ГБ и продолжает увеличиваться.
Кто-нибудь знает, что не так?Любая помощь очень ценится!
Смотрите окно вывода ::
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.Message","time":"2019-02-28T08:48:17.5125091Z","tags":{"ai.internal.nodeName":"V00X6036","ai.operation.name":"GET /DataTaxonomyTool/Index","ai.application.ver":"1.0.0.0","ai.internal.sdkVersion":"aspnet5c:2.1.1","ai.cloud.roleInstance":"V00X6036","ai.location.ip":"127.0.0.1","ai.operation.id":"63f680a6-4a03a53f2cc95492","ai.operation.parentId":"|63f680a6-4a03a53f2cc95492."},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']\r\nSELECT [i].[Id], [i].[ObjectName], [i].[ObjectType]\r\nFROM [Items] AS [i]","severityLevel":"Information","properties":{"commandText":"SELECT [i].[Id], [i].[ObjectName], [i].[ObjectType]\r\nFROM [Items] AS [i]","CategoryName":"Microsoft.EntityFrameworkCore.Database.Command","DeveloperMode":"true","commandType":"Text","{OriginalFormat}":"Executed DbCommand ({elapsed}ms) [Parameters=[{parameters}], CommandType='{commandType}', CommandTimeout='{commandTimeout}']{newLine}{commandText}","elapsed":"1","AspNetCoreEnvironment":"Development","commandTimeout":"30"}}}}
Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [i].[Id], [i].[ObjectName], [i].[ObjectType]
FROM [Items] AS [i]
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.Message","time":"2019-02-28T08:48:17.5378799Z","tags":{"ai.internal.nodeName":"V00X6036","ai.operation.name":"GET /DataTaxonomyTool/Index","ai.application.ver":"1.0.0.0","ai.internal.sdkVersion":"aspnet5c:2.1.1","ai.cloud.roleInstance":"V00X6036","ai.location.ip":"127.0.0.1","ai.operation.id":"63f680a6-4a03a53f2cc95492","ai.operation.parentId":"|63f680a6-4a03a53f2cc95492."},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']\r\nSELECT [i].[Id], [i].[ObjectName], [i].[ObjectType]\r\nFROM [Items] AS [i]","severityLevel":"Information","properties":{"commandText":"SELECT [i].[Id], [i].[ObjectName], [i].[ObjectType]\r\nFROM [Items] AS [i]","CategoryName":"Microsoft.EntityFrameworkCore.Database.Command","DeveloperMode":"true","commandType":"Text","{OriginalFormat}":"Executed DbCommand ({elapsed}ms) [Parameters=[{parameters}], CommandType='{commandType}', CommandTimeout='{commandTimeout}']{newLine}{commandText}","elapsed":"1","AspNetCoreEnvironment":"Development","commandTimeout":"30"}}}}
Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [i].[Id], [i].[ObjectName], [i].[ObjectType]
FROM [Items] AS [i]
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.Message","time":"2019-02-28T08:48:17.5612991Z","tags":{"ai.internal.nodeName":"V00X6036","ai.operation.name":"GET /DataTaxonomyTool/Index","ai.application.ver":"1.0.0.0","ai.internal.sdkVersion":"aspnet5c:2.1.1","ai.cloud.roleInstance":"V00X6036","ai.location.ip":"127.0.0.1","ai.operation.id":"63f680a6-4a03a53f2cc95492","ai.operation.parentId":"|63f680a6-4a03a53f2cc95492."},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']\r\nSELECT [i].[Id], [i].[ObjectName], [i].[ObjectType]\r\nFROM [Items] AS [i]","severityLevel":"Information","properties":{"commandText":"SELECT [i].[Id], [i].[ObjectName], [i].[ObjectType]\r\nFROM [Items] AS [i]","CategoryName":"Microsoft.EntityFrameworkCore.Database.Command","DeveloperMode":"true","commandType":"Text","{OriginalFormat}":"Executed DbCommand ({elapsed}ms) [Parameters=[{parameters}], CommandType='{commandType}', CommandTimeout='{commandTimeout}']{newLine}{commandText}","elapsed":"1","AspNetCoreEnvironment":"Development","commandTimeout":"30"}}}}
Microsoft.EntityFrameworkCore.Database.Command:Information: Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [i].[Id], [i].[ObjectName], [i].[ObjectType]
FROM [Items] AS [i]
Просмотр компонента getMethod:
public class LayoutListsViewComponent : ViewComponent
{
DOOR.Core.Web.Models.ReportContext _context;
public LayoutListsViewComponent(DOOR.Core.Web.Models.ReportContext context)
{
_context = context;
}
public IList<DOOR.Core.Web.Models.DataTaxonomy.Item> items { get; set; }
public async Task<IViewComponentResult> InvokeAsync()
{
var items = await _context.Items
.AsNoTracking()
.ToListAsync();
return View(items);
}
}
Просмотр компонента Default.cshtml:
@model IEnumerable<DOOR.Core.Web.Models.DataTaxonomy.Item>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "~/Pages/DataTaxonomyTool/Layout/LayoutTaxonomy.cshtml";
}
@for (char c = 'A'; c <= 'Z'; c++)
{
<ul style="list-style:none">
<li class="nav-item">
<a class="nav-link" data-toggle="collapse" data-target="#@c.ToString().ToLower()">@c</a>
<div id="@c.ToString().ToLower()" class="collapse">
@foreach (var item in Model.OrderBy(x => x.ObjectName))
{
@if (item.ObjectName.StartsWith(c.ToString().ToLower()))
{
<ul style="list-style:none">
<li>@item.ObjectName</li>
</ul>
}
}
</div>
</li>
</ul>
}
Планировка:
@addTagHelper*,DOOR.Core.Web
<!DOCTYPE html>
<html>
...
<vc:layout-lists></vc:layout-lists>
...