Search code examples
typescriptbreeze

Breeze does not work with predictate in aspnetcore project


I am building an ASP.NET Core project, which uses breezejs and typescript. The mysterious thing is that when I load data without a predicate, all the things work fine, but when a predicate is added to filter the data, there is an error:'500 Internal Server Error' . I tried to debug in the controller, when browser make the request, it can get to the controller.

But, in the js side, the request has no return, which means the js code cannot go through the breakpoint.

executeQuery(query) {
    return this.manager
        .executeQuery(query.using(breeze.FetchStrategy.FromServer || this.fetchStrategy))
        .then(function (data) {
            return data.results;//my breakpoint
        });
}

The contorller:

using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Jumpstart.Web.Data;
using Microsoft.AspNetCore.Authorization;
using Jumpstart.Model;
using Breeze.AspNetCore;
using Newtonsoft.Json.Linq;
using Breeze.Persistence;

namespace Jumpstart.Web.Controllers
{
[Produces("application/json")]
[Route("breeze/[controller]/[action]")]
[BreezeQueryFilter]
public class JumpstartController : Controller
{
    private readonly IUnitOfWork _uitOfWork;

    public JumpstartController(IUnitOfWork uitOfWork)
    {
        _uitOfWork = uitOfWork;
    }

    /// <summary>
    /// Get public tenants
    /// </summary>
    /// <returns>IQueryable tenants</returns>
    [HttpGet]
    [AllowAnonymous]
    public IQueryable<Tenant> Tenants()
    {
        return _uitOfWork.TenantRepository.All();

    }

The request :

Request URL:http://localhost:50481/breeze/Jumpstart/tenants?$filter=Id%20eq%20guid%2709ae9363-240a-46d7-b5a6-30529e7dee63%27&
Request Method:GET
Status Code:500 Internal Server Error

Solution

  • Found the reason. The breeze.core(server end) only permit json format predicate, but the default in breeze front end is not.

    the solution is :

      breeze.config.initializeAdapterInstance("uriBuilder", "json");