title: Entity Framework persisted computed column woes
body: <p>I recently updated a computed column to be persisted due to poor performance when querying it.</p>
  
  <p>However now updates to child records throw this error </p>
  
  <pre><code>System.Data.SqlClient.SqlException
  Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.
  </code></pre>
  
  <p>Having an inner exception of</p>
  
  <pre><code>An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. 
  </code></pre>
  
  <p>This happens with or without an index on the column.</p>
  
  <p>FYI I have a configuration for the column thus:</p>
  
  <pre><code>Property(c =&gt; c.DisplayName).HasColumnName("DISPLAY_NM").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
  </code></pre>
  
  <p>Any workaround?</p>
  
  <p><strong>edit</strong></p>
  
  <p>The child element statement is pretty irrelevant - but here it is. Imagine entities Order, Company (an Order must have a Company). I create an Order with an un-changed Company and its the Company entity with the computed column that is causing the problem - it works fine without the persistence on the computed column (as expected there's 1 insert statement on Order and 0 update statements on Company)</p>
  
  <p>I think <a href="http://msdn.microsoft.com/en-us/library/ms189292.aspx" rel="nofollow">this is the solution</a> but unsure how to do it in EF </p>