public void save(CABECERA_DOCUMENTO obj) { using (gapharmaEntities1 db = new gapharmaEntities1()) { db.CABECERA_DOCUMENTO.Add(obj); db.SaveChanges(); int id = obj.CABECERA_DOCUMENTO_ID; foreach (var item in obj.detalle) { item.CABECERA_DOCUMENTO_ID = id; db.DETALLE_DOCUMENTO.Add(item); db.SaveChanges(); } } }
public void save(PERSONA obj) { using (gapharmaEntities1 db = new gapharmaEntities1()) { try { db.PERSONA.Add(obj); db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } }
public void save(DESTINATARIO obj) { using (gapharmaEntities1 db = new gapharmaEntities1()) { db.DESTINATARIO.Add(obj); db.SaveChanges(); } }