views:

296

answers:

4

Here's my scenario:

  • I have a simple message that is passed in via WCF. this message represents an existing database record and has all of the datafields required to do my calculation.
  • Once I'm done with my calculation, I want to update one field on this datarecord.

Currently, attempting to simply set all of the fields of the Entity framework's version of the entity and then persisting the object context's state seems to do nothing.

any thoughts?

A: 

If you have the entity key as well, you should be able to do the following:

myDataContext.Refres(RefreshMode.ClientWins, Object myEntity);

(Not 100% sure the syntax is exactly that, but I know the method is called .Refresh())...

Tomas Lycken
A: 

Yes you can. The procedure is to make an entity which resembles the original state of the entity, attach it to the ObjectContext, modify the entity, then SaveChanges. Remember, it is important to attach the entity to the ObjectContext before you modify the entity. There is an example in this post.

Craig Stuntz
A: 

Thank you tomas, it works.

A: 

What if I need to update thousands of rows? With SQL the task is trivial: UPDATE [Person] SET [ShortName]='NY' WHERE [TownName]='New York'

How can this be done using EF?

Thanks.