0

Problem: during Insert-operation of entity_A I want to update a property on a specific entity_B and update the changes. I do this as follows:

public void InsertEntity_A(Entity_A entity_A)
{
    // fetch entity_B and change a property
    Entity_B entity_B = ObjectContext.Entity_B.SingleOrDefault(...);
    entity_B.Counter++;
    this.UpdateEntity_B(entity_B);

    // continue normal processing for entity_A
    if((entity_A.EntityState != ...) 
    ...
    ...
}

"UpdateEntity_B(...)" generates an error saying that entity_B is not in the current ChangeSet. How can I achieve this??

TIA Heiko

okieh
  • 617
  • 6
  • 17
  • What does `UpdateEntity()` look like? Does it use a different `ObjectContext`? Does it pull anything from `this.ChangeSet`? – Ed Chapel Jul 25 '12 at 15:24
  • UpdateEntity() is the code that RIA Services has generated and it looks like `this.ObjectContext.Entity_B.AttachAsModified(currentEntity_B, this.ChangeSet.GetOriginal(currentEntity_B));` Since the entity is currently not in the ChangeSet the error pops up. – okieh Aug 03 '12 at 08:11

1 Answers1

0

If found out that using

ObjectContext.Entity_B.ApplyCurrentValues(entity_B);

instead of UpdateEntity() does the trick and obviously saves entity_B to the database. Can anyone confirm that this is the right way to do it?

Regards Heiko

okieh
  • 617
  • 6
  • 17