Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top