简体   繁体   中英

breeze.js plain old sql

I am into the process of evaluating either I should use Breeze.js in my project. I understand that Breeze uses some kind of linq-esque language to send queries to the server and then to the database. Does Breeze.js allow the alternative use of plain old sql? example:

var plain_old_query = EntityQuery.from_plain_old_query('select * from customers where bla bla bla');
manager.executePlainOldQuery(plain_old_query)

In fact the main reason I would like to know if Breeze support this feature is that I will have some very complex queries to make, some very complex whereclause to build. And figuring it out how to build these queries with their linq-esque language -for the moment - would cost a precious time I do not have. Also I would like to know if Breeze.js can work with WCF because most of the examples I have been looking at these fews days are also exclusively with Web API. (In our project we are already making heavy use of WCF). Thank to the community

Breeze does not support SQL query syntax, but you can use Breeze to talk to an endpoint that does. If you use the withParameters feature, you can compose your SQL queries on the server using parameters passed from the client. For example, you could have a server-side method:

    [HttpGet]
    public IQueryable<Customer> CustomersWhoPurchasedProducts(string zipCode, DateTime startDate, DateTime endDate, [FromUri] int[] productIds)
    {
        var query = ComposeCustomerQueryFromParameters(zipCode, startDate, endDate, productIds);
        IQueryable<Customer> results = ExecuteQueryIntoCustomerObjects(query);
        return results;
    }

Note that if your server-side method returns IQueryable<> , then more filtering can be added to the initial result before it is returned to the client. Breeze can add the filtering data to the query. So your Breeze client could call your server method like this:

// query with parameters
var query = EntityQuery.from("CustomersWhoPurchasedProducts")
    .withParameters({ 
        zipCode: 90210, 
        startDate: new Date(2014, 1, 1).toISOString(), 
        endDate: new Date(2014, 4, 1).toISOString(),
        productIds: [911, 928, 935, 944] 
    });

// Add filtering
query = query.where('CompanyName', 'startsWith', 'A');
// Add paging
query = query.skip(20).take(10);

Sorry, I don't have a WCF example to point you to. Conceptually it will be similar to Web API, but you'll need to configure it to return JSON .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM