简体   繁体   English

breeze.js普通的旧sql

[英]breeze.js plain old sql

I am into the process of evaluating either I should use Breeze.js in my project. 我正在评估我应该在项目中使用Breeze.js的过程。 I understand that Breeze uses some kind of linq-esque language to send queries to the server and then to the database. 我知道Breeze使用某种linq式语言将查询发送到服务器,然后再发送到数据库。 Does Breeze.js allow the alternative use of plain old sql? Breeze.js是否允许使用普通的旧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. 实际上,我想知道Breeze是否支持此功能的主要原因是,我将要进行一些非常复杂的查询,并在其中建立一些非常复杂的子句。 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. 并弄清楚目前如何使用其linq式语言构建这些查询将花费我没有的宝贵时间。 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. 我也想知道Breeze.js是否可以与WCF一起使用,因为这几天来我看到的大多数示例都是Web API专用的。 (In our project we are already making heavy use of WCF). (在我们的项目中,我们已经大量使用WCF)。 Thank to the community 感谢社区

Breeze does not support SQL query syntax, but you can use Breeze to talk to an endpoint that does. Breeze不支持SQL查询语法,但是您可以使用Breeze与支持此功能的端点进行对话。 If you use the withParameters feature, you can compose your SQL queries on the server using parameters passed from the client. 如果使用withParameters功能,则可以使用从客户端传递的参数在服务器上编写 SQL查询。 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. 请注意,如果您的服务器端方法返回IQueryable<> ,则可以在初始结果返回到客户端之前对其进行更多过滤。 Breeze can add the filtering data to the query. Breeze可以将过滤数据添加到查询中。 So your Breeze client could call your server method like this: 因此,您的Breeze客户端可以这样调用服务器方法:

// 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. 抱歉,我没有WCF示例供您参考。 Conceptually it will be similar to Web API, but you'll need to configure it to return JSON . 从概念上讲,它将类似于Web API,但您需要对其进行配置以返回JSON

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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