breezejs:getEntityByKey with expand [英] breezejs: getEntityByKey with expand

查看:115
本文介绍了breezejs:getEntityByKey with expand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个Product实体列表。然后我想编辑其中一个产品,所以我打算调用getEntityByKey从缓存中获取它。

Let's say I have a list of Product entities. Then I want to edit one of these products, so I'm going to call getEntityByKey to get it from the cache.

但是在编辑屏幕上,很可能是我将显示比网格中更多的属性,在我的情况下,我实际上需要对某些Product属性执行expand()。

However on the edit screen, it is likely that I'm going to display more properties than in the grid, and in my case I actually need to do an expand() on some of the Product properties.

那么如何我是否处理有关缓存的问题?如果我使用getEntityByKey,它不会执行expand()。我可以执行查询,但后来我没有利用缓存的实体(如果我之前已经编辑过产品)。

So how do I handle that regarding caching ? If I use getEntityByKey, it's not going to do the expand(). I could execute a query, but then I don't take advantage of cached entities (in case I had already edited the Product before).

在这种情况下我应该选择什么策略?

What strategy should I opt for in this case ?

推荐答案

另一种方法:在 Product 实体中添加 isReadyForEdit 标志。如果为false,则使用常规查询来获取完整的 Product WITH EXPAND以获取相关实体。如果这是真的,你知道你拥有缓存中所需的一切, getEntityByKey 就是你所需要的(因为相关实体也将在缓存中)。确保在任何一种情况下都返回一个promise,以便调用者逻辑准备等待。这与John Papa的例子中的 isPartial 相同。

Another approach: add an isReadyForEdit flag to your Product entity. If false, you use a regular query to fetch the full Product WITH EXPAND to get the related entities. If it's true, you know you have everything you need in cache and getEntityByKey is all you need (because the related entities will be in cache as well). Make sure you return a promise in either case so that your caller logic is prepared to wait. This is the same technique as isPartial in John Papa's examples.

忘记提及,与John Papa的例子不同,你的 isReadyForEdit 不应该是未映射的属性,除非您需要序列化其状态(即使那时我也不太确定)。只需将属性添加到实体中即可。

Forgot to mention that, unlike in John Papa's example, your isReadyForEdit should not be an unmapped property unless you need to serialize its state (and even then I'm not so sure). Just add the property to the entity when its true.

不要说JP做错了什么;它适合他的离线场景。但是,如果您不需要Breeze感知功能

Not saying that what JP did was wrong; it fit his offline scenarios. But unmapped property adds unnecessary complexity if you don't need the Breeze-aware features

这篇关于breezejs:getEntityByKey with expand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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