STE ChangeTracker.OriginalValues 始终为空
我无法从 EF STE DTO 获取 OriginalValues。
var _Item = new MyClass();
_Item.StartTracking(); // ChangeTracker.OriginalValues.Count = 0
_Item.Name = "Jerry"; // ChangeTracker.OriginalValues.Count = 0
_Item.Name = "Bob"; // ChangeTracker.OriginalValues.Count = 0
_Item.AcceptChanges(); // ChangeTracker.OriginalValues.Count = 0
_Item.Name = "Sam"; // ChangeTracker.OriginalValues.Count = 0
我做错了什么吗?
谢谢
I am having trouble getting OriginalValues from my EF STE DTO.
var _Item = new MyClass();
_Item.StartTracking(); // ChangeTracker.OriginalValues.Count = 0
_Item.Name = "Jerry"; // ChangeTracker.OriginalValues.Count = 0
_Item.Name = "Bob"; // ChangeTracker.OriginalValues.Count = 0
_Item.AcceptChanges(); // ChangeTracker.OriginalValues.Count = 0
_Item.Name = "Sam"; // ChangeTracker.OriginalValues.Count = 0
Am I doing something wrong?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
整个
ChangeTracker
是您应用程序的一部分 - 它是由 STE T4 模板生成的类,因此您可以轻松跟踪OriginalValues
应该做什么。如果您修改跟踪实体上的导航属性,则
OriginalValues
用于存储原始加载的外键和相关实体。它们不用于通用属性,但您可以根据需要修改模板,并对这些属性使用更改跟踪器。编辑:
您将无法获得公共财产的原始值,因为它没有存储(据我了解模板)。它在 SQL 分析器中也可见。如果您更改具有 50 个属性的实体中的单个标量属性并将更改应用到新上下文,它将创建包含所有 50 个属性的更新(附加实体上的标准更改跟踪将仅传递修改后的属性)。
如果您想知道公共属性的原始值,您必须修改模板以支持此类功能。
Whole
ChangeTracker
is part of your application - it is a class generated by STE T4 template so you can easily track what shouldOriginalValues
do.OriginalValues
are used to store original loaded foreign keys and related entities if you modify navigation property on tracked entity. They are not used for common properties but you can modify template to your needs and use change tracker for these properties as well.Edit:
You will not get original value of common property because it is not stored (as I understand the template). It is also visible in SQL profiler. If you change single scalar property in entity which have 50 properties and apply changes to the new context it will create update with all 50 properties (standard change tracking on attached entity would pass only that modified property).
If you want to know original value of common property you must modify template to support such feature.