2011-06-06 74 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); 
     }