c# - Entity Framework 在查询中创建一个不存在的列

标签 c# oracle entity-framework ef-code-first

这让我困惑了很长一段时间,但当我的 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/

相关文章:

c# - 取消删除 Google 日历事件

java - 使用瘦 jdbc 驱动程序创建 oracle 数据库触发器

sql - 一个或另一列中的值

c# - 没有等待的异步编程?

c# - EF Code First 中的多对多关系表示

c# - 如何将事件从 Facade 附加到另一个类

c# - 尽管指定了 .Returns,最小起订量对象仍返回 null

c# - DataAdapter.Fill() 在加载大的十进制值时抛出溢出异常

c# - 如何强制进行新的空 EF 迁移?

c# - 如何从一个 List<T> 中删除在另一个 List<T> 中找到的重复项?