0

I want to load an entity from the and set only one property and Update it in the Db but only by updating the property I have changed.

How can I achieve that?

var goodFood = Repository.FoodRepository.GetByID(100);
good.Food.SaltLevel = Salt.NoSalt;

// Now how to SAve it back without touching any other fields 
//and only updating the SaltLevel field?
pencilCake
  • 51,323
  • 85
  • 226
  • 363
  • Just call `DataContext.Save()` ?? – Habib Nov 26 '13 at 16:56
  • But I do not want it to override other fields. Bcoz other process running in parallel might have updated some other fields. But imagine SaltLevel is only updated from this piece of code. – pencilCake Nov 26 '13 at 16:57
  • you would encounter a concurrency exception if other fields changed since you loaded the entity – Moho Nov 26 '13 at 16:58
  • When the goodFood is loaded, some other app can already update some other fields (I tried to simplify with food example) – pencilCake Nov 26 '13 at 16:58
  • @Moho, this is what I doubt in my case... – pencilCake Nov 26 '13 at 16:59
  • @pencilCake - there's a slew of potential solutions for you in this [SO Post](http://stackoverflow.com/questions/3642371/how-to-update-only-one-field-using-entity-framework). – Stinky Towel Nov 26 '13 at 17:08

0 Answers0