Answer the question
In order to leave comments, you need to log in
How to fix error in EntityModel?
Hello. After executing this query, namely after join
var patients = from TD in ConnectControl.MHE.Doctors
join TPatientCards in ConnectControl.MHE.PatientCard on TD.idDoctor equals TPatientCards.idDoctor
select new
{
pc = TPatientCards.idPatientCard
};
An error occurred while executing the command definition
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class PatientCard
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public PatientCard()
{
this.MedAppointments = new HashSet<MedAppointments>();
this.Patients = new HashSet<Patients>();
this.Procedure = new HashSet<Procedure>();
}
[Key]
public int idPatientCard { get; set; }
public int idDoctor { get; set; }
public int idRoom { get; set; }
public string diagnosis { get; set; }
public virtual Doctors Doctors { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<MedAppointments> MedAppointments { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Patients> Patients { get; set; }
public virtual Rooms Rooms { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Procedure> Procedure { get; set; }
}
Answer the question
In order to leave comments, you need to log in
How do you set up relationships between tables? Without any additional configuration, EF expects the <class_name>_Id property.
As Konstantin Kosyanov wrote , if there are no additional link settings (for example, via the Fluent API), then EF follows the foreign key naming convention, which the code does not match. In this case, you need to add the ForeignKey attribute with the name of the corresponding navigation property:
[ForeignKey("Doctors")]
public int idDoctor { get; set; }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question