何时在Entity Framework 4中使用ApplyOriginalValues? [英] When to use ApplyOriginalValues in Entity Framework 4?

查看:139
本文介绍了何时在Entity Framework 4中使用ApplyOriginalValues?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了ApplyCurrentValues。

I have used ApplyCurrentValues.

但是真的不了解ApplyOriginalValues。与ApplicationCurrentValues有什么不同?我应该什么时候使用?

But don't really understand ApplyOriginalValues. How is it different from ApplyCurrentValues? When should I use it?

我已阅读文档。但仍然困惑。

I have read the documentation. But still confused.

推荐答案

从数据库加载的每个实体都保留两组值 - 原始(加载表单DB)和当前(你正在修改的)。这两个集合保存在 ObjectStateEntry 中。通常每个保存都接受接受当前值并将其写入原始值的更改。如果您知道您对EF外部的实体进行了更改(例如通过使用常见的ADO.NET EF调用存储过程),可以强制EF了解这些更改,而无需使用 ApplyOriginalValues 。我认为使用这种方法是相当罕见的。例如,我在 ApplyOriginalValues 5327770#5327770>这个答案

Each entity loaded from the database keeps two sets of values - original (those loaded form DB) and current (those you are modifying). These two sets are hold in ObjectStateEntry. Usually each save is followed by accepting changes which takes current values and writes them to original values. If you know that you made changes to the entity outside of EF (for example by calling stored procedure with common ADO.NET EF) you can force EF to know about those changes without reloading the entity by using ApplyOriginalValues. I think using this method is rather rare. For example I used ApplyOriginalValues in this answer.

这篇关于何时在Entity Framework 4中使用ApplyOriginalValues?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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