I want to update an employee record in my SQL 2005 database which is already in my employees EntityCollection . The method I am using is as follows:
1) Load the employee data from the database into a new Entity called "modifiedEntity" (this gives me fresh version of the data).
2) Make changes to modifiedEntity and save it back to the database
To update the employees EntityCollection:
3) Find the original employee entity in employees and delete it.
4) Add modifiedEntity to employees.
Steps (1) and (2) proceed as expected.
In step (3) the old entity is deleted from employees. In the debugger I can still see the record is still in employees, but all of the fields are blanked out and the Fields.State shows as Deleted.
Step (4) fails with the message "This entity is deleted from the database and can't be used in logic.". In the debugger I can see modifiedEntity along with all of the correct field values and Fields.State = New. The original entity record in employees as in step (3).
I don't really understand what is happening here and why this doesn't work?
Thanks