4

我有以下数据库:

在此处输入图像描述

我已经从这个数据库中创建了 EDMX 模型。

一切都很好,直到我将Diagnosis表格添加到图表中。

下面的查询开始出错:

var appointments = from a in db.Appointment.Include("Patient")
                   where a.DoctorID == doctorId
                   select a;

我开始收到以下错误:

列名“DiagnosisID”无效。

在调试模式下,我检查了生成的数据库查询,它是:

SELECT 
  [Extent1].[ID] AS [ID], 
  [Extent1].[DoctorID] AS [DoctorID], 
  [Extent1].[PatientID] AS [PatientID], 
  [Extent1].[DiagnosisID] AS [DiagnosisID], 
  [Extent1].[Date] AS [Date], 
  [Extent1].[Time] AS [Time], 
  [Extent1].[Duration] AS [Duration], 
  [Extent1].[Notes] AS [Notes], 
  [Extent2].[ID] AS [ID1], 
  [Extent2].[ContactDetailID] AS [ContactDetailID], 
  [Extent2].[FirstName] AS [FirstName], 
  [Extent2].[LastName] AS [LastName], 
  [Extent2].[Sex] AS [Sex], 
  [Extent2].[BirthDate] AS [BirthDate], 
  [Extent2].[CurrentDate] AS [CurrentDate], 
  [Extent2].[Notes] AS [Notes1]
FROM  [dbo].[Appointment] AS [Extent1]
LEFT OUTER JOIN [dbo].[Patient] AS [Extent2] ON [Extent1].[PatientID] = [Extent2].[ID]
WHERE (([Extent1].[DoctorID] = @p__linq__0) AND ( NOT ([Extent1].[DoctorID] IS NULL OR @p__linq__0 IS NULL))) OR (([Extent1].[DoctorID] IS NULL) AND (@p__linq__0 IS NULL))

/*
Int32 p__linq__0 = 1
*/

我的设计有什么问题吗?

以下是约会表设计:

在此处输入图像描述

这是约会表的 FK 定义:

在此处输入图像描述

一旦我调用可枚举对象的ToList()方法,就会发生异常,如下所示:

在此处输入图像描述

EF生成的类如下:


public partial class Appointment
    {
        public int ID { get; set; }
        public Nullable<int> DoctorID { get; set; }
        public Nullable<int> PatientID { get; set; }
        public Nullable<int> DiagnosisID { get; set; }
        public Nullable<System.DateTime> Date { get; set; }
        public Nullable<System.DateTime> Time { get; set; }
        public Nullable<byte> Duration { get; set; }
        public string Notes { get; set; }

        public virtual Diagnosis Diagnosis { get; set; }
        public virtual Doctor Doctor { get; set; }
        public virtual Patient Patient { get; set; }
    }

public partial class Diagnosis
    {
        public Diagnosis()
        {
            this.Appointment = new HashSet<Appointment>();
        }

        public int ID { get; set; }
        public string Symptoms { get; set; }
        public string Treatment { get; set; }
        public Nullable<System.DateTime> CurrentDate { get; set; }
        public string Notes { get; set; }

        public virtual ICollection<Appointment> Appointment { get; set; }
    }

EDMX 生成的类如下:

在此处输入图像描述

4

1 回答 1

0

我刚刚发现了问题。它在连接字符串中!我忘记更改指向生产服务器的连接字符串,并且我没有将更改的数据库同步回生产数据库。

谢谢你们的努力。

于 2013-08-23T15:50:58.807 回答