How to properly send action parameter along with query in BreezeJs

前端 未结 2 1162
别那么骄傲
别那么骄傲 2021-01-02 00:45

Currently I am calling all data queries as showed on BreezeJs docs / examples:

getEntityList = function (predicate) {
  var query = new entityModel.EntityQ         


        
相关标签:
2条回答
  • 2021-01-02 01:03

    UPDATE: AS OF BREEZE v.0.76.1 THIS IS NO LONGER THE CORRECT ANSWER. BREEZE NOW SUPPORTS PARAMETERS ON QUERIES. SEE THE "withParameters" QUERY CLAUSE.

    Support for parameterized queries was added to Breeze thanks in part to this question on SO. Thank you.

    This answer used to describe a workaround which is no longer needed. I have revised my answer, eliminating my description of that workaround.

    0 讨论(0)
  • 2021-01-02 01:17

    As of v 0.76.1, you can use the EntityQuery.withParameters method to pass additional parameters to any service method. So you can now construct a query like the following that both passes parameters and uses breeze's IQueryable support.

    EntityQuery.from("EmployeesFilteredByCountryAndBirthdate")
                     .withParameters({ BirthDate: "1/1/1960", Country: "USA" })
                     .where("LastName", "startsWith", "S")
                     .orderBy("BirthDate");
    

    where your controller method would look something like this:

    [HttpGet]
    public IQueryable<Employee> EmployeesFilteredByCountryAndBirthdate(DateTime birthDate, string country) {
          return ContextProvider.Context.Employees.Where(emp => emp.BirthDate >= birthDate && emp.Country == country);
    }
    

    The API docs have more information.

    0 讨论(0)
提交回复
热议问题