导出导入模式和hasTempKey问题 [英] Exporting Importing Breeze Model and hasTempKey issues

查看:160
本文介绍了导出导入模式和hasTempKey问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建新实体Breeze set id:-1 state:'added'hasTempKey:true。导出和重新导入后,Breeze不将import -1实体与当前的-1实体合并到内存中,它会添加一个新的实体...这在docs ...中解释(但是我们如何克服这个问题呢?在我的情况下的问题...)所以我试图将创建的实体设置为setUnchanged();现在,导出导入周期按预期运行,但是创建的实体已经丢失了它的hasTempKey:true属性,所以新创建的实体可以与当前的实体冲突...如何解决这些问题的一些建议真的将不胜感激,谢谢

When you create a new entity Breeze set id:-1 state:'Added' hasTempKey:true. After export and re-import Breeze doesn't merge the import -1 entity with the current -1 entity in memory it adds a new one... this is explain in the docs... ( but how do we overcome this problem is the question in my case... ) So I tried to set the entity created to setUnchanged(); Now the export import cycle runs as expected but the created entity has lost it's hasTempKey:true property so newly created entity can conflict with a current one... some advice on how to resolve these issues would really be appreciated thanks

推荐答案

我认为这个问题涉及到您实现断开连接的应用程序的方法,如在这个SO问题

I assume that this question relates to your approach to implementing a disconnected app as described in this SO question.

正如我所说,我花了太多时间试图欺骗微风做不应该做的事情。例如,您需要 EntityManager.saveChanges 实际上不保存到远程数据存储。但是,saveChanges的全部内容是永久性持续存在。 本地保存并不是真正的保存。没有人,但你知道这些保存的变化。您不知道他们是否会在您的服务器上传递业务验证规则,或者是否会与其他用户的更改相冲突。如果您的笔记本电脑死机或被盗,则本地保存的数据将消失。

As I said there, I you're spending too much time trying to trick Breeze into doing what it should not do. Here, for example, you want EntityManager.saveChanges to not actually save to the remote data store. But the whole point of "saveChanges" is that it persists permanently. "Saving locally" is not really saving. No one but you knows about these saved changes. You don't know if they would pass the business validation rules on your server or if they would collide with a different user's changes. If your laptop dies or is stolen, your locally saved data are gone.

我认为微风可以帮助制作偶尔连接的应用程序。但是,我认为在本地适当地区分更改本地更改的意图至关重要,以保存这些更改,并远程保存。

I think breeze can be a huge help in crafting occasionally connected applications. But I think it is critical to properly differentiate stashing changes locally with the intent to save them and actually saving them remotely.

我敦促你采取不同的方向。

I urge you to take a different tack.

您的应用程序可以轻松启动不同编辑会话的顺序。例如,一个会话可能是客户'A'的旅行预订,客户'B'的另一个会话,第三个会话是完全相关的...也许客户端'C'的配置文件。

Your app could easily initiate a sequence of distinct editing sessions. For example, one session could be a travel reservation for client 'A', another session for client 'B', and a third session is about something else entirely ... maybe the client 'C' profile.

当您的应用无法访问服务器时,它将每个会话保留为WIP(正在进行中)。每个WIP会话都有自己的序列化包,由WIP密钥标识。

When your app can't reach the server, it preserves each session as a WIP ("Work In Progress"). Each WIP session its own serialized bundle, identified by a WIP key.


另外:你会在John Papa的使用角度和微风构建应用程序第2部分今年晚些时候出现。

Aside: you'll see this pattern in John Papa's "Building Apps with Angular and Breeze Part 2" when that comes out later this year.

Breeze EntityManager.exportEntities(list_of_entities)序列化关于该会话的更改实体的所有内容,包括其更改状态,原始值和临时密钥。请记住, list_of_entities 可以是任何东西,包括对象图。您可以将该捆绑包保存在WIP密钥下的浏览器本地存储中,并在以后恢复。

The Breeze EntityManager.exportEntities(list_of_entities) serializes everything about the changed entities of that session including their change-state, original values, and temp keys. Remember that the list_of_entities can be anything including an object graph. You can save that bundle to browser local storage under the WIP key and restore it later.

我将保留一个WIP会话目录,其中包含有关会话作为一个整体(例如,什么样的编辑会话,以及这个会话是否准备好远程持久化)。您的应用程序在离线时向用户显示WIP会话。当它获得连接时,它会经历一个同步阶段,在此期间它尝试持久化更改。运气好成功。如果没有,您可以在UI中补充会话,并帮助用户调和冲突。

I'd keep a directory of WIP sessions that included information about the state of the session as a whole (e.g., what kind of editing session it is and whether this session was ready to be persisted remotely). Your app presents WIP sessions to the user while offline. When it gets a connection, it goes through a "synchronization" phase during which it tries to persist the changes. With luck it succeeds. If not, you can rehydrate the session in the UI and help the user reconcile the conflicts.

这些是广泛的笔画。恶魔在细节中。

These are broad strokes. The devil is in the details.

在这种情况下,关键的是你不会混淆实体状态或临时密钥。你不在乎钥匙是什么,还是改变的。序列化的会话将为您保存该状态信息。序列化的捆绑包将进出本地存储而不用投诉。您正在使用Breeze,而在线或线上。

The critical thing in this context is that you do not mess with entity state or the temp keys. You don't care what the keys are or if they change. The serialized session will hold that state information for you. The serialized bundles will move in and out of local storage without complaint. You are using Breeze as intended, while offline or online.

这篇关于导出导入模式和hasTempKey问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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