web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Pablo Peralta's Blog / EntityState must be set to ...

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

Pablo Peralta Profile Picture Pablo Peralta 793

Hi,

When trying to update an Entity by using LINQ query provider in Dynamics CRM 201 this way:

 
regardingOpportunity.PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, rateCard.Id);
MyXrmServiceContext.Update(regardingOpportunity);

.. I came across the following exception:

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

 

Pretty odd but in my case I get it to work by just using method UpdateObject instead of Update:

regardingOpportunity.PriceLevelId = new EntityReference(PriceLevel.EntityLogicalName, rateCard.Id);
MyXrmServiceContext.UpdateObject(regardingOpportunity);
 
MyXrmServiceContext.SaveChanges();  

 

Apparently (honestly not sure), by using UpdateObject record is marked as modified and that allows to save it later.

 

Hope it helps to save somebody else’s time.

 

PP [twitter: @pabloperalta]

UruIT Dynamix | Excellence in Dynamics CRM Nearshoring Services.

Comments

*This post is locked for comments