Entity Framework 5.0 strange problem

I have the following database:

enter image description here

I created an EDMX model from this database.

Everything worked fine until I added the Diagnosis table to the chart.

As a result of the request below, errors were made:

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

I started getting the following error:

Invalid column name 'DiagnosisID'.

In debug mode, I checked the generated database query, and that was:

 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 */ 

Is there something wrong with my design?

Below is the design of the Destination table:

enter image description here

And here is the FK definition for the destination table:

enter image description here

An exception occurs when I call the ToList () method of an enumerated object, as shown below:

enter image description here

The generated EF classes are as follows:

 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; } } 

The generated EDMX classes are as follows:

enter image description here

+4
source share
1 answer

I just found a problem. It was on the connection string! I forgot to change the conenction line because it was pointing to the production server, and I did not synchronize the database that was changed back to the production database.

Thank you guys for your efforts.

0
source

Source: https://habr.com/ru/post/1497560/


All Articles