Azure MobileApp Controller returns 500 only if IQueryable return type

My backend for the azure mobile app presents strange behavior. If my controller action returns IQueryable<T>, and the type of the object has a navigation property, it returns 500.

A simple example:

Model

public class ProductHierarchy : EntityData
{
    public string Name { get; set; }

    public string Description { get; set; }

    public DateTime ValidFrom { get; set; }

    public DateTime ValidTo { get; set; }

    public string BrandId{ get; set; }
    [ForeignKey("BrandId")]
    public virtual Brand Brand { get; set; }

    public ProductStatus Status { get; set; }

    public int CreatedBy { get; set; }

    public int ModifiedBy { get; set; }
}

Controller action

[HttpGet]
    [Route("api/ProductHierarchies/FromBrand/{brandId}")]
    public IQueryable<ProductHierarchy> FromBrand(int brandId)
    {
        var hierarchies = Query().Where(hi => hi.Brand.OldBrandId ==brandId);
        return hierarchies;
    }

When I make a request for this action, with the solution running on my local machine, everything works fine, however, when I publish the solution for azure, the action FromBrandstarts returning 500, with a general message

"An error has occurred."

In addition, Azure Logs shows me the following exception when I request an action:

Detailed Error Information: Module
__DynamicModule_Microsoft.Owin.Host.SystemWeb.OwinHttpModule,Microsoft.Owin.Host .SystemWeb, Version=3.0.1.0,  Culture=neutral,PublicKeyToken=31bf3856ad364e35_19e9f0a3-023d-4d8b-83ef- 180a415e7921 Notification PreExecuteRequestHandler Handler ExtensionlessUrlHandler-Integrated-4.0 Error Code 0x00000000

I found two changes that can avoid the error:

1) Brand JsonIgnore, Brand

2) List<ProductHierarchy>, Brand JsonIgnore, .

, IQueryable<T>, T .

, , nuget, . , - Newtonsoft Json AutoMapper.

- , ?

+4

Source: https://habr.com/ru/post/1661101/


All Articles