[Resolved] – EntityState must be set to null, Created (for Create message) or Changed (for Update message)

Recently I was facing an issue with Update of a record in the Plugin. The error message was as ‘EntityState must be set to null, Created (for Create message) or Changed (for Update message)’.

The plugin was written on Post-Operation of Create action.

After looking for the resolution for the issue, I came across a solution posted online, which I am not sure, is supported, but worked for me.

Before calling the _service.Update(Entity), You need to change the state of entity as below:

recordToUpdate.EntityState = EntityState.Changed;

Hope this helps.

Also there is another approach to resolve this:

Instead of using

context.Update(object),

Use:

context.UpdateObject(object)

Reference:

http://stackoverflow.com/questions/6187978/entitystate-must-be-set-to-null-created-for-create-message-or-changed-for-u

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s