这让我困惑了很长一段时间,但当我的 Entity Framework 尝试执行 oracle 查询时,我不断收到无效标识符错误。有问题的类如下:
public class Projectship : ModelTrackingBase
{
[Column("PROJECTID")]
public long ProjectId { get; set; }
[Column("VISITID")]
public long VisitId { get; set; }
public virtual Bpid Bpid { get; set; } //new
public virtual Visit Visit { get; set; }
}
和
public class Bpid : EntityIdBase
{
[Column("BUDPRJID")]
[MaxLength(38)]
public string BPId { get; set; }
[Column("DESCRIPTION")]
[MaxLength(255)]
public string Description { get; set; }
[Column("CSTOBJ")]
[MaxLength(255)]
public string Custobj { get; set; }
[Column("PVID")]
[MaxLength(255)]
public string Pvid { get; set; }
public virtual ICollection<Projectship> Projectships { get; set; }
public IEnumerable<Visit> Visits
{
get { return Projectships.Select(p => p.Visit); }
}
[NotMapped]
public string DisplayName
{
get { return string.Format("{0}: {1}", BPId , Description); }
}
}
现在 EntityIdBase 具有以下内容:
public class EntityIdBase : EntityBase
{
[Column("ID")]
public long Id { get; set; }
}
它会尝试在查询中继续查找 Bpid_Id 列。有人知道吗?
最佳答案
bpid_id是EF创建的,因为它不能自动判断关系。尝试添加注释:
[ForeignKey("ID")]
public virtual Bpid Bpid { get; set; } //new
关于c# - Entity Framework 在查询中创建一个不存在的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28699357/