I'm using EF 6.1 code first in my project. For following entity, I want to increment Version
field value in database when onlyCode
and Name
values changed(I update my Entities in a disconnected scenario):
public class Product
{
public int Id {get; set;}
public string Code {get; set;}
public string Name {get; set;}
public string Title {get; set;}
public int Version {get; set;}
}
Using [TimeStamp]
annotation cause the [TimeStamp]
property changes when any property value of entity change.
Is there any way to do this work in EF?
You can check the state of the property changed or not.Here MSDN Link
You update code may look like this.