【问题标题】:aspnetboilerplate internal 500 error on recursive entity lookup递归实体查找时出现 aspnetboilerplate 内部 500 错误
【发布时间】:2018-02-19 15:08:39
【问题描述】:

查询递归实体查找时出现以下错误。

错误

{"message":"发生错误。","exceptionMessage":"有一个为 api 控制器应用程序/类别定义的操作 GetCategories 但使用不同的 HTTP 动词。请求动词是 GET。它应该是 Post","exceptionType":"System.Web.HttpException","stackTrace":" at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.GetActionDescriptorByActionName(HttpControllerContext controllerContext, DynamicApiControllerInfo controllerInfo, String actionName)\r\n at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n 在 System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancelToken)\r\n 在 Castle.Proxies.DynamicApiController@987654321 @1.Intercept(IInvocation 调用)\r\n at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n at Castle.Proxies.DynamicApiController`1Proxy_5.ExecuteAsync(HttpControllerContext controllerContext, Ca ncellationToken cancelToken)\r\n 在 System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"}

该错误仅在我添加第一个具有ParentId 的条目后发生

型号

     [Table("Categories")]
     public class Category : FullAuditedEntity
     {
        [Required]
        public string Name { get; set; }
        [Required]
        public string SharepointMapping { get; set; }
        public int? ParentId { get; set; }
        public Category Parent { get; set; }
       public List<Category> Children { get; set; }
     }

CategoryAppService

  public ListResultDto<CategoryListDto> GetCategories(GetCategoriesInput input)
  {
    var categories = _categoryRepository
        .GetAll()
        .WhereIf(
            !input.Filter.IsNullOrEmpty(),
            p => p.Name.Contains(input.Filter) 
        )
        .OrderBy(p => p.Name)
        .ToList();

        return new ListResultDto<CategoryListDto>(categories.MapTo<List<CategoryListDto>>());
  }

CategoryListDto

[AutoMapFrom(typeof(Category))]
public class CategoryListDto : FullAuditedEntityDto
{
    public string Name { get; set; }
    public string SharepointMapping { get; set; }
    public int? ParentId { get; set; }
    public virtual Category Parent { get; set; }       
}

【问题讨论】:

    标签: c# asp.net-mvc entity-framework recursion aspnetboilerplate


    【解决方案1】:

    所有 WebApi 方法的默认 http-verb 是 POST。 使用 POST 提出请求。


    如果您不喜欢这个解决方案,您可以使用常规动词。对于常规动词,它查找方法名称前缀并匹配相关的 http-verb。

    • GetCategories -> HTTP-GET
    • DeleteCategory -> HTTP-DELETE
    • UpdateCategory -> HTTP-PUT
    • CreateCategory -> HTTP-POST

    您可以使用WithConventionalVerbs方法,如下所示:

    Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder
        .ForAll<IApplicationService>(Assembly.GetAssembly(typeof(SimpleTaskSystemApplicationModule)), "tasksystem")
        .WithConventionalVerbs()
        .Build();
    

    更多信息: https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API

    【讨论】:

    • 您的解决方案解决了一半的问题,以帮助找到根本原因,即自引用 Json 错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    相关资源
    最近更新 更多