MSDN Archive Home
Help and FAQs
Persistence Ignorance (POCO) Adapter for Entity Framework
All Resource Updates
Create New Discussion
Problem with ApplyPropertyChanges
Oct 2 2009 at 4:02 PM
I am experiencing a strange problem using ApplyPropertyChanges.
In my Business Layer, I receive the POCO instance containing the updated values. I update two fixed values then pass it to the update method in the EF layer. This is the code in the BL:
myItem.UpdatedOn = DateTime.Now;
myItem.UpdateBy = this._provider.Context.Users.First(c => c.Username == "someUsername");
Item updated = this._provider.UpdateItem(myItem);
Then my method in the EF layer does the following:
string id = myItem.ID;
Item current = this.Context.Items.First(c => c.ID == id);
I get an exception saying that the entity is in an ADDED state and cannot be updated. The message refers to the User that I put in the "UpdatedBy" field, because if I comment out that line, everything works fine. Now the User instance was just retrieved from the Context, it should be still attached and so in an Unchanged state, not added.
Am I doing something wrong, or it's just a bug? What can I do to fix this?
Sign in to post message or set email notifications
Manage Your Profile
MSDN Flash Newsletter
© 2008 Microsoft Corporation. All rights reserved.