2011-06-06 22 views
0

我最近更新了一個計算列以便在查詢時由於性能較差而被保留。實體框架持久計算列困境

然而現在更新到子記錄拋出這個錯誤

System.Data.SqlClient.SqlException 
Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services. 

具有

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. 

內部異常出現這種情況有或沒有在列的索引。

FYI我有這樣的柱的結構:

Property(c => c.DisplayName).HasColumnName("DISPLAY_NM").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed); 

任何變通方法?

編輯

子元素的語句是相當無關 - 但在這裏它是。想象一下實體Order,Company(一個訂單必須有一個公司)。我創建了一個訂單,其中包含一個未更改的公司和它的公司實體,其計算列引起了這個問題 - 它在沒有計算列的持久性的情況下工作正常(如預期的那樣,訂單上有1條插入聲明,公司有0條更新聲明)

我覺得this is the solution,但不確定該怎麼做,在EF

+0

這將需要更多的信息來了解你的問題。你指的是兒童記錄,但我們不知道什麼是孩子,什麼是父母,以及你做了什麼變化。 – 2011-06-06 11:10:47

+0

看到我上面的編輯 – 2011-06-06 11:46:24

+0

並不總是這樣,公司沒有更新:http://stackoverflow.com/questions/6232185/ef4-update-table-set-p-0-where首先檢查數據庫中發生了什麼層使用SQL事件探查器。 – 2011-06-06 12:12:34

回答

0

我加入相關實體的ID作爲屬性(在表essentialy暴露FK值解決類似的問題),並創造記錄時,如果我只分配相關對象ID暴露FK屬性,一切正常,不需要相關對象。

你可以看到同時具有相關的對象實體的樣品並使用EF流體測繪here其ID映射:

public ThingMap() 
     { 
      this.Property(t => t.Name) 
       .IsRequired() 
       .IsMaxLength() 
       .IsUnicode(); 

      //// Table mappings 
      this.ToTable("Things", "go"); 
      this.Property(t => t.Name).HasColumnName("Name"); 
      this.Property(t => t.TypeId).HasColumnName("Type_Id"); 

      //// References 
      this.HasRequired(t => t.Type) 
       .WithMany(t => t.Things) 
       .HasForeignKey(t => t.TypeId); 
     }