EFCore报告“无效的列名”

时间:2019-12-11 13:16:12

标签: c# entity-framework entity-framework-core

我的设置如下。我有一个很大的JobModel,但这是重要的部分:

public class JobModel 
{
    public int JobId { get; set; }
    public int ProcessId { get; set; }
    public ProcessModel Process { get; set; } // Uses ProcessId as foreign key
    public int StatusId { get; set; }
    public StatusModel Status { get; set; } // Uses StatusId as foreign key
    public ProcessStatusModel ProcessStatus { get; set; } // Uses ProcessId and StatusId as foreign key

    // Rest of the class is irrelevant to this issue...
}

JobModel通过Fluent API在Entity Framework核心中配置,如下所示:

modelBuilder.Entity<JobModel>(job =>
{
    job.ToTable("Job").HasKey(j => j.JobId);
    job.HasOne(j => j.Process);
    job.HasOne(j => j.Status);
    job.HasOne(j => j.ProcessStatus);
});       

我尝试通过服务方法来检索数据(我故意离开Debug.WriteLine,因为他们证明存在某种联系):

public async Task<List<JobModel>> GetJobs(ProcessModel process)
{
    // Returns 'Found 1932 jobs...'
    Debug.WriteLine($"Found { context.Jobs.Count() } jobs...");

    // Returns 'Found 10 process statuses'
    Debug.WriteLine($"Found {context.ProcessStatuses.Count() } process statuses...");

    // No issues here
    var jobs = context.Jobs
        .Where(j => j.IsDeleted == false
                 && j.ProcessId == process.ProcessId
                 && (j.IsDone == false || j.ModifiedDtm > DateTime.Now.AddDays(-2)));

    // This throws an exception
    return await jobs.ToListAsync();
}

抛出的异常类型为SqlException,异常消息为:

  

无效的列名'ProcessStatusProcessId'。
  无效的列名'ProcessStatusStatusId'。

我在做什么鸭子?它曾经在一些(不相关的)代码更改和软件包更新之前工作。

我正在使用.NET Framework 4.7和Entity Framework Core 3.1.0

0 个答案:

没有答案