Breeze 不适用于 asp net core 项目中的谓词

Breeze does not work with predictate in aspnetcore project

我正在构建一个 ASP.NET 核心项目,它使用了 breezejs 和 typescript。奇怪的是,当我在没有谓词的情况下加载数据时,一切正常,但是当添加谓词来过滤数据时,出现错误:'500 Internal Server Error'。我尝试在controller中调试,当浏览器发出请求时,它可以到达controller。

但是,在js端,request没有return,也就是说js代码无法走断点

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

控制器:

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();

    }

要求:

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

找到原因了。 breeze.core(server端)只允许json格式谓词,breeze前端默认不允许。

解决方案是:

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