Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6886279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:44:22+00:00 2026-05-27T05:44:22+00:00

If I modify a property of a POCO Entity, but reset it the EntityFramework

  • 0

If I modify a property of a POCO Entity, but reset it the EntityFramework still says that there are changes.

Property "Name": Value "Test" (original value) 
              -> Value "Test123" (value changed by UI) 
              -> Value "Test" (value changed by UI to original value)

Entries that have been modified:

var objectStateEntries = 
    _db.ObjectStateManager.GetObjectStateEntries(
        EntityState.Added | 
        EntityState.Deleted | 
        EntityState.Modified);

How do you handle this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:44:22+00:00Added an answer on May 27, 2026 at 5:44 am

    If all your properties are virtual Entity Framework will automatically create a dynamic proxy of your POCO by default. If I am not wrong change tracking is based in this case on property setters of this dynamic object, roughly like so:

    private string _name;
    public string Name
    {
        // ...
        set
        {
            // if (_name != value) such a check probably does not happen
            {
                _name = value;
                MarkPropertyAsModified(...);
            }
        }
    }
    

    So, there is no comparison with the original value, but only with the current value of the property. If this value gets changed the property is marked as modified, no matter if you reset it back to the original value.

    (Edit and correction of the previous paragraph: The property is marked as Modified if the setter is called, no matter if the same or a changed value is assigned. Thanks to Brad Thomas and his comment below!)

    You can avoid creating dynamic proxies by disabling this in the context options:

    objectContext.ContextOptions.ProxyCreationEnabled = false;
    

    Change detection will now rely on snapshot creation, which means that EF compares the original value (stored in a snapshot in the object context) with the current value when change detection is called. This does not happen anymore in property setters but inside of certain functions of Entity Framework, for example in SaveChanges. In your situation it would mean that when you call SaveChanges original value (snapshot) and current value will be the same because you did reset the change. Basically EF didn’t notice that you changed the property twice and considers the property as unchanged.

    Be aware that disabling proxy creation – if you do it globally, for example in the context constructor – is a potentially deep change for your application. You might have code which depends on dynamic proxies in order to work correctly and it also can affect performance heavily in various situations. Dynamic proxies exist to make change tracking fast. Snapshot based change tracking is much slower.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to modify the property values in a Properties file that
I have an Entity Framework POCO class that is generated by a T4 Template.
I found out, that UITableView modify contentSize property and I can't set it by
The official documentation says to modify an entity I retrieve a DbEntityEntry object and
I want to be able to modify the value property of a trackbar in
How does one change / modify the Result property of a web service operation?
What is the more rails-like? If I want to modify a model's property when
I'm trying to modify my GreaseMonkey script from firing on window.onload to window.DOMContentLoaded, but
Is it possible to modify a registry value (whether string or DWORD) via a
How can I modify a SharePoint site so that versioning is turned on by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.