title: "EntityState must be set to null, Created (for Create message) or Changed (for Update message)" when attempting to update an entity in CRM 2011
body: <p>I am using the following code to update an entity. </p>
  
  <pre><code>Service.Update(_policy);
  </code></pre>
  
  <p>where policy is a class generated using CrmSvcUtil.exe</p>
  
  <pre><code>public partial class new_policy : Microsoft.Xrm.Sdk.Entity, System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
  </code></pre>
  
  <p>I retrieve the policies using LINQ, then update one attribute (an EntityReference) and then attempt the update</p>
  
  <p>When this code runs I get the following error message:</p>
  
  <blockquote>
    <p>EntityState must be set to null, Created (for Create message) or
    Changed (for Update message)</p>
  </blockquote>
  
  <p>There are other entities generated in the same way that I can update.</p>
  
  <p>I tried </p>
  
  <pre><code>_policy.EntityState = EntityState.Changed
  </code></pre>
  
  <p>but then I get a message saying </p>
  
  <blockquote>
    <p>The entity is read-only and the 'EntityState' property cannot be
    modified. Use the context to update the entity instead.</p>
  </blockquote>
  
  <p>Does anyone know what is causing this?</p>