How Come this is not allowed?
public void addInsertedInformationToDb() {
using(DbClassesDataContext myDb = new DbClassesDataContext(dbPath)){
myDb.PatientInfos.InsertOnSubmit(insertPersonalInformation);
}
}
Where my insertPersonalInformation
private PatientInfo insertPersonalInformation()
{
DbClassesDataContext myDb = new DbClassesDataContext(dbPath);
PatientInfo patientInfo = new PatientInfo();
patientInfo.Phy_ID = physcianID;
patientInfo.Pat_First_Name = txtFirstName.Text;
patientInfo.Pat_Middle_Name = txtMiddleName.Text;
patientInfo.Pat_Last_Name = txtLastName.Text;
patientInfo.Pat_Gender = cmbGender.Text;
patientInfo.Pat_Marital_Status = cmbMaritalStatus.Text;
patientInfo.Pat_Date_Of_Birth = dtpDOB.Value;
patientInfo.Pat_Home_Add = txtHomeAdd.Text;
patientInfo.Pat_Home_Num = txtPhone.Text;
patientInfo.Pat_Work_Add = txtWorkAdd.Text;
patientInfo.Pat_Work_Num = txtWorkPhone.Text;
patientInfo.Pat_Prim_Physician = txtPrimPhysician.Text;
patientInfo.Pat_Ref_Physician = txtRefePhysician.Text;
return patientInfo;
}
I kept on getting these errors
Error 1 The best overloaded method match for ‘System.Data.Linq.Table.InsertOnSubmit(PatientAdministration.PatientInfo)’ has some invalid arguments C:\Users\John\documents\visual studio 2010\Projects\PatientAdministration\PatientAdministration\Pat_Demog.cs 101 17 PatientAdministration
Error 2 Argument 1: cannot convert from ‘method group’ to ‘PatientAdministration.PatientInfo’ C:\Users\John\documents\visual studio 2010\Projects\PatientAdministration\PatientAdministration\Pat_Demog.cs 101 50 PatientAdministration
What is the fix for this?
Because in InsertOnSubmit you can just use entity object or valid expressions not calling arbitrary methods, linq2entity can’t convert your method to required expression, You can do as below to come up with your problem:
See Insert with linq2entity:
Finally don’t forgot to call
myDb.SubmitChanges().