我在.net Core Web应用程序中执行视图组件时遇到问题。我已经使用过几次了,没有问题,但是这次却表现得有些滑稽。
在输出窗口中,我可以清楚地看到Visual Studio正在尝试从数据库查询数据,但是此命令每秒被无数次执行一次无数个项目,直到我停止应用程序为止(结果当然是t渲染)。
我还注意到一段时间后使用的内存约为2.5GB,并且仍在增加。
有人知道怎么了吗?任何帮助,不胜感激!
查看输出窗口::
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>
...
答案 0 :(得分:0)
愚蠢的我-调用Default.cshtml时,我忘记删除此部分:
@{
Layout = "~/Pages/DataTaxonomyTool/Layout/LayoutTaxonomy.cshtml";
}
我使用此视图组件以相同的布局获取一些数据。因此程序陷入了无限循环。