1

I am using EF 6 with WPF. Since I have to work with lots of DataSets, I have to use AsNoTracking() with the queries. Thus, updating any of the entries is now a responsibility of the ViewModel. I am using repository pattern, and I am thinking of implementing a method in the generic repository like this:

virtual public void Update(T updatedentity)
{
    _ctx.Set<T>().Attach(updatedentity);
    _ctx.Entry(updatedentity).State = EntityState.Modified;
}

Is this a good idea? What are the pros and cons of this approach? And finally, will there be the significant performance hit? A point to note here, most of my entities have at most 15-20 attributes.

Mighty Badaboom
  • 6,067
  • 5
  • 34
  • 51

1 Answers1

0

Yes, you can/should attach entities that already exist in the database and then setting it's state to Modified will force all T entity properties to be updated.

You can read a good explanation of Attach method here: Entity Framework 4 - AddObject vs Attach Please also read possible impacts of EntityState.Modified here @Gert answer: Entity Framework - Why explicitly set entity state to modified?

Ricardo Serra
  • 374
  • 2
  • 11