using (var context = new Entities()) { try { var record = (from p in context.Patient.Include("PatientAddress") where p.PatientId == patient.PatientId select p).FirstOrDefault(); if (record == null) { context.AddToPatient(patient); } else { foreach (var item in patient.PatientAddress) { if (item.EntityKey == null) { context.AddToPatientAddress(item); // <--Throws Exception here. continue; } context.ApplyPropertyChanges("PatientAddress", item); } context.ApplyPropertyChanges("Patient", patient); } context.SaveChanges(); return true; } catch { return false; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)