I created an application that uses Asp.net, Entity Framework, and the Windows Workflow Foundation, and everything works as expected.
My asp.net page should launch Workflow, which executes and updates the object passed to the workflow from the page. Everything works fine: I used the Unit Of Work template to exchange context between asp.net and WWF, and my entity was successfully updated during the workflow ... except for the field, which was modeled in my entity as a reference to another object.
Assume this case. The main object is called Item, which has a property called Status, which is the foreign key for another object called Status. When I create an element, I just create it using the usual syntax like
Item i = new Item();
Then I create a link to the Status object as follows:
i.StatusReference.EntityKey = new System.Data.EntityKey("myEntities.StatusSet", "idStatus", State);
where State is an integer value hardcoded in the Workflow step.
Whenever I try to update this Entity (Item one), I do the following: a) I retrieve the Entity from the context (new, built as Unit of Work for the next transaction) using:
Item i = (from item in ctx.ItemsSet where item.idItem == itemID select item).FirstOrDefault();
The entity is then attached to my context. EntityState is in UNCHANGED
b) I am updating the Status link as before:
i.StatusReference.EntityKey = new System.Data.EntityKey("myEntities.StatusSet", "idStatus", State);
c) I save changes in context, for example: ctx.SaveChanges ();
Using the vs2008 debugger, I can see the updated object and when the changes are saved ... I see that all properties are changed (modifiedDate, itemName and other details), but the link to the object still points to the original one.
Can anybody help me?