inner join in JayData

£可爱£侵袭症+ 提交于 2019-12-11 13:46:14

问题


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

and how it could be possible?


回答1:


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

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.

Entity and context definition:

$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) query orders by customer:

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

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


来源:https://stackoverflow.com/questions/11222134/inner-join-in-jaydata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!