Timothy
Timothy

Reputation: 618

EntityFramework get changed/modified properties after SaveChanges()

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

Answers (2)

Timothy
Timothy

Reputation: 618

db.Entry(vehicle).GetDatabaseValues()

I found this and it seems to work. Now I just need to compare them

Upvotes: 0

Disappointed
Disappointed

Reputation: 1120

Look at this

DbContext.Entry(vehicle).OriginalValues

And compare these values with your input vehicle

Upvotes: 1

Related Questions