开发者

How does EF4 determines if a property has really changed?

开发者 https://www.devze.com 2023-01-27 22:53 出处:网络
I need a way to track modified pr开发者_JAVA技巧operties and audit them. I am hooking into SaveChanges where I get the modified properties

I need a way to track modified pr开发者_JAVA技巧operties and audit them. I am hooking into SaveChanges where I get the modified properties

   //Get only Modified Customer entries
   var modifiedCustomerOses = context.ObjectStateManager
     .GetObjectStateEntries<Customer>(EntityState.Modified)
     .ToList();

What I have noticed and I am using EF4 with codeGeneration that it reports when a property is not really modified as modified. If a property EG "CustomerName" is set to "John" and when I do an update I dont change the name but I do EntityCustomer.Name=customerDto.Name and the name are exactly the same it still reports as changed.

I have looked at the generated code and cannot see if EF property does a check like

if(name==value)//propertyNotchanged dont raiseevent.

Any suggestions? Do you know how EF4 determines if a property has really changed?

thanks


The tracking is performed on entity level, not on property level.
The more appropriate way to trace if the property was changed is to use the OnPropertyChanged partial method.
Just create a custom code that will hold the changed properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消