aspnetboilerplate内部500错误的递归实体查找

时间:2017-09-11 11:27:06

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

在查询递归实体查找时,我收到以下错误。

错误

  

{&#34; message&#34;:&#34;发生了错误。&#34;,&#34; exceptionMessage&#34;:&#34;有针对GetCategories定义的操作api控制器app / category但具有不同的HTTP动词。请求动词是GET。它应该是Post&#34;,&#34; exceptionType&#34;:&#34; System.Web.HttpException&#34;,&#34; stackTrace&#34;:&#34; 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在Castle.Proxies.DynamicApiController 1Proxy_5.ExecuteAsync_callback(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at Castle.Proxies.Invocations.ApiController_ExecuteAsync_5.InvokeMethodOnTarget()\r\n at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n at Abp.WebApi.Controllers.Dynamic.Interceptors.AbpDynamicApiControllerInterceptor处的System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken)\ r \ n中1.在Castle.DynamicProxy.AbstractInvocation中接受(IInvocation调用)\ r \ n。继续()\ r \ n在Castle.Proxies.DynamicApiController`1Proxy_5.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken)\ r \ n在System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()&#34;} < / em>的

仅在添加具有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; }       
}

1 个答案:

答案 0 :(得分:1)

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

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

  • GetCategories - &gt; HTTP-GET
  • DeleteCategory - &gt; HTTP-DELETE
  • UpdateCategory - &gt; HTTP-PUT
  • CreateCategory - &gt; HTTP-POST

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

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

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