EventEntry.ToJson() tracks all properties at changes when Entity.State sets to Modified
See original GitHub issueHey Federico š
I realize one thing. It may work as expected fine but I donāt think so.
Before we are updating an entity. If we set our entity objectās EntityState as Modified. Audit writes as all the properties into Jsonās changes array. Actually, I only changed 1 or 2 property.
Letās see with an example;
public class Category : AuditableEntity<int>
{
public string Title { get; set; }
public string Description { get; set; }
// .. more prop goes ..
}
// Let's say I retrieved category object from the data source in the category variable
category.Title = "new updated title";
// We don't updated any other props.
_context.Entry(category).State = EntityState.Modified;
await _context.SaveChangesAsync()
My expectation to see only category title in the Jsonās changes array but all of the category property will be there. š
Thanks for the great projects and helps! ššš
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Entity Framework - Why explicitly set entity state to modified?
It is purpose of change tracking to find that you have changed a value on attached entity and put it to modified state....
Read more >Working with entity states - EF6
Modified : the entity is being tracked by the context and exists in the database, and some or all of its property values...
Read more >JS | Change Tracking
Change tracking. Breeze entities are āself-trackingā which means that each entity instance keeps track of its own changed state ā¦ and much more....
Read more >Configuration Management Platform Wireless User's Guide
Viewing Subscriber Entity States Associated with a Subscriber ... The audit log records all notification server actions (create, modify, and delete), policy.
Read more >Monitoring and Diagnostics
The Time Line allows you to view status and health information for a specific point in time or across a range of time....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, you are right. But if I donāt set Entity State as modified (I think even if we set it should not break changes), somehow changeTracker.Entries() elements are not set to modified. I also override SaveChanges. If my entity updated I need to know it to update run some internal logic.
But to anyone usage, I solve it by using the following lines before called base.SaveChangesAsync(cancellationToken);
I also donāt get it why it is happening. I can close the issue, probably it is a specific case donāt know why?
Thanks for your time.
I donāt get itā¦ If you only change the Title property, why would you want to track the unmodified properties?
This should be enough: