我有一个奇怪的问题。我在我的应用程序中使用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 property
到PlotDescription
模型,其中包含ProposedWorks2
属性。即使这个属性存在于PlotDescription模型中,它存在于数据库中,我收到以下错误:
这是TreeElement
和PlotDescription
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; }
.....
}
您能否告知如何解决此问题?