Reputation: 618
I have a very simple web api method that looks like this:
public void Put(Vehicle vehicle)
{
db.Entry(vehicle).State = EntityState.Modified;
db.SaveChanges();
}
All it does is updating the direct properties of the vehicle entity. This works fine like this. But I would now like to know which properties have actually changed? Is there a way to do this?
I probably could get the vehicle from the database first and then compare it to the modified vehicle. But maybe there is an easier way.
Thanks
Upvotes: 2
Views: 2567
Reputation: 618
db.Entry(vehicle).GetDatabaseValues()
I found this and it seems to work. Now I just need to compare them
Upvotes: 0
Reputation: 1120
Look at this
DbContext.Entry(vehicle).OriginalValues
And compare these values with your input vehicle
Upvotes: 1