虽然列存在,但列名称无效,而不是ID,Entityframework

时间:2017-11-20 07:32:52

标签: c# entity-framework

我有一个奇怪的问题。我在我的应用程序中使用Entity Framework。 在一个简单的循环数据库项目中,我不断获得Invalid column name error

 var list = ggisContext.TreeElements.Where(x => x.PlotDescription != null && x.VolumeElementActualUa > 0).ToList();
  foreach(var item in list)
  {...}

列表中填充了元素,当我到达foreach时,错误就开始了 TreeElements具有虚拟navigation propertyPlotDescription模型,其中包含ProposedWorks2属性。即使这个属性存在于PlotDescription模型中,它存在于数据库中,我收到以下错误: enter image description here

这是TreeElementPlotDescription class

public class TreeElement
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    [ForeignKey("PlotDescription")]

    public int? PlotDescriptionId { get; set; }
    public int? TreeId { get; set; }
    public int? RegenerationModeId { get; set; }
    public int? OriginId { get; set; }
    [ForeignKey("PlotDescriptionId")]
    public virtual PlotDescription PlotDescription { get; set; }
    .......
}

public class PlotDescription
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    public int? ProductionUnitId { get; set; }
    public string Plot { get; set; }
    public string SubPlot { get; set; }
    public string ProposedWorks1 { get; set; }
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public string ProposedWorks2 { get; set; }
     .....
}

您能否告知如何解决此问题?

0 个答案:

没有答案