0

I am getting the following error on the following procedure

public Patient getPatientByPatientId(int PatientID)
{
    Patient patient = new Patient();
    if (PatientID == -1)
    {
       patient = new Patient();
    }
     else
    {
       using (var myContext = new SMBASchedulerEntities(this.Connectionstring))
        {
                patient = myContext.Patients
               .Where(w => w.PatientID == Convert.ToString(PatientID)).FirstOrDefault();
         }
        }
        return patient;
}

The error is

n unhandled exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll

Additional information: LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method, and this method cannot be translated into a store expression.

YODA
  • 1

1 Answers1

0

Convert your code

patient = myContext.Patients.Where(w => w.PatientID == Convert.ToString(PatientID)).FirstOrDefault();

to

patient = myContext.Patients.Where(w => w.PatientID ==PatientId.ToString()).FirstOrDefault();

Above query with assuming that PatientId is String

But Error says LINQ to Entities does not recognize the method 'System.String ToString(**Int32**)' method

Means PatientId is Int.

Then try with following code

patient = myContext.Patients.Where(w => w.PatientID ==PatientId).FirstOrDefault();
Ehsan Ullah Nazir
  • 1,827
  • 1
  • 14
  • 20