c# - LINQ to Entities does not recognize the method ,and this method cannot be translated into a store expression -


i have following code data using ef , try converting them model below.

var patients = allpatients.select(p => createpatient(p));      public patient createpatient(patient p)         {             patient patient = new patient();              patient.firstname = p.firstname;             patient.middlename = p.middlename;             patient.surname = p.surname;              return patient;         } 

but getting error

"linq entities not recognize method 'model.patient createpatient(repository.patient)' method, , method cannot translated store expression."

you can create new patient objects in linq select:

var patients = allpatients.select(p => new patient()  {             firstname = p.firstname,             middlename = p.middlename,             surname = p.surname         }); 

or define patient constructor accepts patient object , initializes values of provided patient:

public partial class patient {     public patient(patient p)     {         this.firstname = p.firstname;         this.middlename = p.middlename;         this.surname = p.surname;     } } 

and use in linq select:

var patients = allpatients.select(p => new patient(p)); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -