JayData中的内部联接 [英] inner join in JayData

查看:83
本文介绍了JayData中的内部联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JayData库,我想知道可以在JayData中模拟内部联接,例如:

I use JayData liberary and I want to know that it is possible to simulate inner join in JayData, like:

Customers inner join Orders on
Customers.CustomerID = Orders.CustomerID

以及它怎么可能?

推荐答案

在当前版本中,JayData尚不支持一般的AdHoc联接.不过,它在路线图上.

AdHoc joins in general are not yet supported by JayData in the current release. It's on the roadmap though.

但是,根据您的需求和基础数据提供者,可以通过多种方式实现类似的行为.我假设您正在使用OData提供程序.

It is however possible to achieve similar behavior on a number of ways, depending on your needs and the underlying data provider. I assume you are using the OData provider.

在这种情况下,您可以使用导航属性来表示关系,从而在查询上实现隐式联接.

In this case you can use navigation properties to represent the relation and thus achieve an implicit join on queryies.

实体和上下文定义:

$data.Entity.extend("Customer", {
 Id: { key: true, computed: true, type: 'int' },
 Name: { type:string },
 Orders: { type: $data.EntitySet, elementType: 'Order', inverseProperty: 'Customer' }
});

$data.Entity.extend("Order" {
 Id: { key: true, computed: true, type: 'int' },
 Customer: { type: Customer, inverseProperty: 'Orders' }
});

$data.EntityCotnext.extend("CustomerOrders", {
  Customers: { type: $data.EntitySet, elementType: Customer },
  Orders: { type: $Data.EntitySet, elementType: Order }
});

1)按客户查询订单:

1) query orders by customer:

context.Orders.filter( function(order) {
  return order.Customer.Name.startsWith('John');
}).toArray(...)

2)通过订单查询客户:这是JayData 1.1中发布的新功能(请确保更新您的文件)

2) query customer by orders: this is new feature released in JayData 1.1 (make sure to update your files)

ordersQuery = context.Orders.filter( function(order) { return order.Value > 200 });

context.Customers.filter( function(customer) {
 return custom.Orders.some(ordersQuery);
}).toArray(...);

这篇关于JayData中的内部联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆