public static string Generater() { PCMSDBContext dbContext = new PCMSDBContext(); PcmsId id = new PcmsId(); using (System.Data.Entity.DbContextTransaction dbTran = dbContext.Database.BeginTransaction()) { try { dbContext.PcmsIds.Add(id); dbContext.SaveChanges(); id.KEY = String.Format("P{0:D6}", id.ID); dbContext.SaveChanges(); dbTran.Commit(); } catch (Exception e) { log.Error(e); dbTran.Rollback(); } dbTran.Dispose(); } return(id.KEY); }
public void Delete(SchoolQPaper_entities entities, int PPRODR01_id) { bool dispose = entities == null; entities = entities ?? new SchoolQPaper_entities(); System.Data.Entity.DbContextTransaction trans = null; if (dispose) { trans = entities.Database.BeginTransaction(); } entities.TRN_PaperOrder01_D.Where(x => x.PPRODR01_id == PPRODR01_id).ToList().ForEach(r => { new TRN_PaperOrder01_D_Class().Delete(entities, r.PPRODR01D_id); }); new TRN_PaperOrder01_H_Class().Delete(entities, PPRODR01_id); int RECEIVABLES_id = entities.TRN_Receivable.Where(x => x.RECEIVABLES_doc_id == PPRODR01_id && x.DOCU_id == Misc.Properties.DBs.SchoolQPaper.dbo.MST_Document.Records.Up_to_O_L_Invoice).FirstOrDefault().RECEIVABLES_id; entities.TRN_Receivable.Where(x => x.RECEIVABLES_ref_id != null && x.RECEIVABLES_ref_id == RECEIVABLES_id && x.DOCU_id == Misc.Properties.DBs.SchoolQPaper.dbo.MST_Document.Records.Receipt).ToList().ForEach(r => { new Receipt.Receipt_Class().Delete(entities, r.RECEIVABLES_doc_id); }); new TRN_Receivable_Class().Delete(entities, RECEIVABLES_id); if (dispose) { trans.Commit(); trans.Dispose(); entities.Dispose(); } }
} // BeginTransaction /// <summary> /// Commits the transaction /// </summary> public void Commit() { if (isTopMostTransaction && dbContextTransaction != null) { dbContextTransaction.Commit(); dbContextTransaction.Dispose(); dbContextTransaction = null; } } // Commit
/// <summary> /// Commit started transaction in EF db context /// </summary> /// <remarks>See details about exception in debug</remarks> public void CommitTransaction() { try { _transaction.Commit(); } catch (NullReferenceException ex) { Debug.WriteLine("You didn't start transaction!"); throw new Exception($"Exception: {ex.Message}"); } catch (Exception ex) { Debug.WriteLine($"Exception: {ex.Message}"); _transaction.Dispose(); throw new Exception($"Exception: {ex.Message}"); } _transaction.Dispose(); }
/// <summary> /// Database context for Payroll Database /// </summary> protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { if (DbContextTransaction != null) { DbContextTransaction.Dispose(); } PayrollContext?.Dispose(); } } _disposed = true; }
protected virtual void Dispose(bool disposing) { //_logger.Info("Disposing ..."); if (!_disposed) { if (disposing) { if (DbContextTransaction != null) { DbContextTransaction.Dispose(); } if (PalprimesContext != null) { PalprimesContext.Dispose(); } } } _disposed = true; }
public void Delete(SchoolQPaper_entities entities, int RECEIPT_id) { bool dispose = entities == null; entities = entities ?? new SchoolQPaper_entities(); System.Data.Entity.DbContextTransaction trans = null; if (dispose) { trans = entities.Database.BeginTransaction(); } entities.TRN_Receipt_PayType.ToList().ForEach(r => { if (r.TRN_Receipt_MO_Info.Count != 0) { new TRN_Receipt_MO_Info_Class().Delete(entities, r.TRN_Receipt_MO_Info.FirstOrDefault().RECEIPTMO_id); } if (r.TRN_Receipt_CHQ_Info.Count != 0) { new TRN_Receipt_CHQ_Info_Class().Delete(entities, r.TRN_Receipt_CHQ_Info.FirstOrDefault().RECEIPTCHQ_id); } new TRN_Receipt_PayType_Class().Delete(entities, r.RECEIPTPAYTYP_id); }); entities.TRN_Receipt_D.ToList().ForEach(r => { new TRN_Receipt_D_Class().Delete(entities, r.RECEIPTD_id); }); new TRN_Receipt_H_Class().Delete(entities, RECEIPT_id); new TRN_Receivable_Class().Delete(entities, entities.TRN_Receivable.Where(x => x.RECEIVABLES_doc_id == RECEIPT_id && x.DOCU_id == Misc.Properties.DBs.SchoolQPaper.dbo.MST_Document.Records.Receipt).FirstOrDefault().RECEIVABLES_id); if (dispose) { trans.Commit(); trans.Dispose(); entities.Dispose(); } }
private void MyLog(string channelname, BoundType bound, BatchStatus status, string message) { using (System.Data.Entity.DbContextTransaction dbTran = upsertContext.Database.BeginTransaction()) { try { Batch batch = new Batch { name = channelname, bound = bound, status = status, message = message }; upsertContext.Batches.Add(batch); upsertContext.SaveChanges(); dbTran.Commit(); } catch (Exception e) { log.Error(e); dbTran.Rollback(); } dbTran.Dispose(); } }
private void publishlog(string user, string ip, string path, string rtype, string param) { using (System.Data.Entity.DbContextTransaction dbTran = dbContext.Database.BeginTransaction()) { try { Userlog batch = new Userlog { username = user, ip = ip, url = path, reqtype = rtype, parameters = param }; dbContext.Userlogs.Add(batch); dbContext.SaveChanges(); dbTran.Commit(); } catch (Exception e) { Console.WriteLine(e.Message); dbTran.Rollback(); } dbTran.Dispose(); } }
public bool Put(int id, string value) { int affecteRecordCount = 0; try { // Starts connecting to the database... using (PetSureDatabaseEntities dbo = new PetSureDatabaseEntities()) { // Start the database transaction to ensure that the Entity Framework executes commands on the database within the context of that transaction... using (System.Data.Entity.DbContextTransaction transaction = dbo.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted)) { try { // Finds the id of the pet and update it value... PetList petList = dbo.PetLists.Find(id); petList.PetName = value; dbo.PetLists.Add(petList); dbo.Entry(petList).State = System.Data.Entity.EntityState.Modified; affecteRecordCount = dbo.SaveChanges(); // Commits the underlying store transaction... transaction.Commit(); } catch (Exception) { // ROLLBACK TRANSACTION FOR ANY UNHANDLED EXCEPTION... transaction.Rollback(); } finally { // CLEANS UP TRANSACTION OBJECT AND ENSURES THE ENTITY FRAMEWORK IS NO LONGER USING THAT TRANSACTION... transaction.Dispose(); } } } return(affecteRecordCount >= 0 ? true : false); } catch (Exception) { return(affecteRecordCount >= 0 ? true : false); } }
// GET api/<controller>/5 /// <summary> /// Provides a list of Pet Names for PetSure Web Application System. /// </summary> /// <param name="id">The pet id to retrive data.</param> /// <returns>Returns a Pet Name base on the given id.</returns> public List <PetList> Get(int id) { // Starts connecting to the database... using (PetSureDatabaseEntities dbo = new PetSureDatabaseEntities()) { // Start the database transaction to ensure that the Entity Framework executes commands on the database within the context of that transaction... using (System.Data.Entity.DbContextTransaction transaction = dbo.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted)) { try { // Get the available list of Pet Name on the database... this.petList.Clear(); var petListQuery = from o in dbo.PetLists where o.PetId == id select new { o.PetId, o.PetName }; foreach (var list in petListQuery) { this.petList.Add(new PetList { PetId = list.PetId, PetName = list.PetName }); } // Returns the pet list... return(this.petList); } catch (Exception) { // ROLLBACK TRANSACTION FOR ANY UNHANDLED EXCEPTION... transaction.Rollback(); return(this.petList); } finally { // CLEANS UP TRANSACTION OBJECT AND ENSURES THE ENTITY FRAMEWORK IS NO LONGER USING THAT TRANSACTION... transaction.Dispose(); } } } }
public TRN_Receipt_H Save(SchoolQPaper_entities entities, string RECEIPT_code, DateTime RECEIPT_date, DateTime RECEIPT_tran_date, decimal RECEIPT_amount, string RECEIPT_remarks, string RECEIPT_font, int?SCHL_id, int?AGENT_id, Data.Grid_DS.DS_Receipt DS_Receipt_Obj) { bool dispose = entities == null; entities = entities ?? new SchoolQPaper_entities(); TRN_Receipt_H receipth_rec = null; System.Data.Entity.DbContextTransaction trans = null; if (dispose) { trans = entities.Database.BeginTransaction(); } try { RECEIPT_code = new Document.Document_Class().GetDocumentCode(entities, Misc.Properties.DBs.SchoolQPaper.dbo.MST_Document.Records.Receipt); receipth_rec = new TRN_Receipt_H_Class().Insert(entities, RECEIPT_code, RECEIPT_date, RECEIPT_tran_date, RECEIPT_amount, RECEIPT_remarks, RECEIPT_font, SCHL_id, AGENT_id); DS_Receipt_Obj.OutstandingInvoices.ToList().ForEach(r => { if (r.RECEIPTD_amount != 0) { new TRN_Receipt_D_Class().Insert(entities, r.RECEIPTD_amount, r.RECEIPTD_doc_id, receipth_rec.RECEIPT_id, r.DOCU_id); var outstanding_receivable_rec = entities.TRN_Receivable.Where(x => x.RECEIVABLES_doc_id == r.RECEIPTD_doc_id && x.DOCU_id == r.DOCU_id).FirstOrDefault(); if (outstanding_receivable_rec.RECEIVABLES_balance - r.RECEIPTD_amount < 0) { throw new AppErrorException("Invalid Receipt Amount", "The receipt amount exceeds the outstanding balance on " + r.RECEIPTD_doc_text + "."); } new TRN_Receivable_Class().Update(entities, outstanding_receivable_rec.RECEIVABLES_id, outstanding_receivable_rec.RECEIVABLES_doc_id, outstanding_receivable_rec.RECEIVABLES_value, outstanding_receivable_rec.RECEIVABLES_balance - r.RECEIPTD_amount, outstanding_receivable_rec.RECEIVABLES_ref_id, outstanding_receivable_rec.DOCU_id); new TRN_Receivable_Class().Insert(entities, receipth_rec.RECEIPT_id, r.RECEIPTD_amount, 0, outstanding_receivable_rec.RECEIVABLES_id, Misc.Properties.DBs.SchoolQPaper.dbo.MST_Document.Records.Receipt); } }); DS_Receipt_Obj.PayTypes.ToList().ForEach(r => { var receiptpaytype_rec = new TRN_Receipt_PayType_Class().Insert(entities, r.RECEIPTPAYTYP_amount, r.PAYTYP_id, receipth_rec.RECEIPT_id); if (r.PAYTYP_id == Misc.Properties.DBs.SchoolQPaper.dbo.MST_PayType.Records.MO) { var moneyorderinfo_rec = DS_Receipt_Obj.MoneyOrderInfo.Where(x => x.PayTypes_Id == r.Id).FirstOrDefault(); new TRN_Receipt_MO_Info_Class().Insert(entities, moneyorderinfo_rec.RECEIPTMO_date, moneyorderinfo_rec.RECEIPTMO_no, moneyorderinfo_rec.RECEIPTMO_office, receiptpaytype_rec.RECEIPTPAYTYP_id); } else if (r.PAYTYP_id == Misc.Properties.DBs.SchoolQPaper.dbo.MST_PayType.Records.Cheque) { var chequeinfo_rec = DS_Receipt_Obj.ChequeInfo.Where(x => x.PayTypes_Id == r.Id).FirstOrDefault(); new TRN_Receipt_CHQ_Info_Class().Insert(entities, chequeinfo_rec.RECEIPTCHQ_chq_no, chequeinfo_rec.RECEIPTCHQ_date, receiptpaytype_rec.RECEIPTPAYTYP_id); } }); if (dispose) { trans.Commit(); } } catch (Exception ex) { if (dispose) { trans.Rollback(); } throw ex; } if (dispose) { trans.Dispose(); entities.Dispose(); } return(receipth_rec); }
public bool AddNewDataWithDtls(Hr_RequestTypes ObjHdrDL, List <Hr_RequestTypesDtls> ListDtls) { StackFrame stackFrame = new StackFrame(); MethodBase methodBase = stackFrame.GetMethod(); var strErrorMessage = string.Empty; // ObjWorkFlow_HdrDL.InsUser = "******"; ObjHdrDL.InsDate = DateTime.Now; // ObjCommTransHeaderDL.InsDate = DateTime.Now.ToString("dd/MM/yyyy"); bool result = true; using (System.Data.Entity.DbContextTransaction dbTran = objPharmaEntities.Database.BeginTransaction()) { try { if (objPharmaEntities.Database.Connection.State == System.Data.ConnectionState.Closed) { objPharmaEntities.Database.Connection.Open(); } Hr_RequestTypes loclHdr = new Hr_RequestTypes { Request_Id = ObjHdrDL.Request_Id, Request_Name = ObjHdrDL.Request_Name, Request_NameEn = ObjHdrDL.Request_NameEn, AttachIsNecessary = ObjHdrDL.AttachIsNecessary, RequestType = ObjHdrDL.RequestType, VactionIndivisible = ObjHdrDL.VactionIndivisible, SendOnlyToManger = ObjHdrDL.SendOnlyToManger, InsUser = ObjHdrDL.InsUser, InsDate = ObjHdrDL.InsDate }; objPharmaEntities.Hr_RequestTypes.Add(loclHdr); //saves all above operations within one transaction objPharmaEntities.SaveChanges(); foreach (Hr_RequestTypesDtls Obj_Dtls in ListDtls) { if (Obj_Dtls != null) { Hr_RequestTypesDtls loclDtls = new Hr_RequestTypesDtls { RequestTypeId = loclHdr.Request_Id, RequestDiscountType = Obj_Dtls.RequestDiscountType, RequestTypeValue = Obj_Dtls.RequestTypeValue, RequestRatioValue = Obj_Dtls.RequestRatioValue, }; objPharmaEntities.Hr_RequestTypesDtls.Add(loclDtls); //saves all above operations within one transaction objPharmaEntities.SaveChanges(); } } //commit transaction dbTran.Commit(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); strErrorMessage = fullErrorMessage; // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); //((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors.First().ValidationErrors.First().ErrorMessage dbTran.Rollback(); result = false; } catch (Exception ex) { //Rollback transaction if exception occurs dbTran.Rollback(); result = false; } finally { objPharmaEntities.Database.Connection.Close(); dbTran.Dispose(); if (!string.IsNullOrEmpty(strErrorMessage)) { SaveErrorLog(System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(), strErrorMessage, this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString()); } } return(result); } }
public void Dispose() { _dbContextTransaction.Dispose(); }
public void Dispose() { _uow = null; _trans.Dispose(); }
public TRN_PaperOrder01_H Save(SchoolQPaper_entities entities, string PPRODR01_code, DateTime PPRODR01_datetime, string PPRODR01_remarks, decimal PPRODR01_advanced_pay, string PPRODR01_cheque_no, string PPRODR01_mo_office, int PPRODR01_additional_papers, string PPRODR01_font, decimal PPRODR01_gross_tot, decimal PPRODR01_discount_amnt, decimal PPRODR01_net_tot, decimal PPRODR01_discount_percnt, string PPRODR01_telephone, string PPRODR01_train_received_by, string PPRODR01_train_received_by_nic, Tuple <int?, string> MST_TrainStation_rec, int SCHL_id, int DELIMETH_id, int PAYTYP_id, List <PaperOrderD_Rec> PaperOrderD_Recs) { bool dispose = entities == null; entities = entities ?? new SchoolQPaper_entities(); TRN_PaperOrder01_H paperorder01_rec = null; System.Data.Entity.DbContextTransaction trans = null; if (dispose) { trans = entities.Database.BeginTransaction(); } try { if (MST_TrainStation_rec.Item1 != null && MST_TrainStation_rec.Item1 == 0) { var trainstation_rec = new MST_TrainStation_Class().Insert(entities, MST_TrainStation_rec.Item2, PPRODR01_font); MST_TrainStation_rec = new Tuple <int?, string>(trainstation_rec.TRAINST_id, trainstation_rec.TRAINST_name); } PPRODR01_code = new Document.Document_Class().GetDocumentCode(entities, Misc.Properties.DBs.SchoolQPaper.dbo.MST_Document.Records.Up_to_O_L_Invoice); paperorder01_rec = new TRN_PaperOrder01_H_Class().Insert(entities, PPRODR01_code, PPRODR01_datetime, PPRODR01_remarks, PPRODR01_advanced_pay, PPRODR01_cheque_no, PPRODR01_mo_office, PPRODR01_additional_papers, PPRODR01_font, PPRODR01_gross_tot, PPRODR01_discount_amnt, PPRODR01_net_tot, PPRODR01_discount_percnt, PPRODR01_telephone, PPRODR01_train_received_by, PPRODR01_train_received_by_nic, MST_TrainStation_rec.Item1, SCHL_id, DELIMETH_id, PAYTYP_id); PaperOrderD_Recs.ForEach(r => { new TRN_PaperOrder01_D_Class().Insert(entities, r.PPRODR01D_paper_qty, r.PPRODR01D_ignore_qty, r.GRADE_id, r.SUBJ_id, paperorder01_rec.PPRODR01_id); }); new TRN_Receivable_Class().Insert(entities, paperorder01_rec.PPRODR01_id, PPRODR01_net_tot, PPRODR01_net_tot, null, Misc.Properties.DBs.SchoolQPaper.dbo.MST_Document.Records.Up_to_O_L_Invoice); if (PPRODR01_advanced_pay != 0) { DS_Receipt DS_Receipt_Obj = new DS_Receipt(); DS_Receipt_Obj.OutstandingInvoices.AddOutstandingInvoicesRow(paperorder01_rec.PPRODR01_id, Misc.Properties.DBs.SchoolQPaper.dbo.MST_Document.Records.Up_to_O_L_Invoice, PPRODR01_code, PPRODR01_advanced_pay, PPRODR01_net_tot, SCHL_id, "", "", Settings.Default.CurrentFont); int PayTypes_Id = DS_Receipt_Obj.PayTypes.AddPayTypesRow(PAYTYP_id, "", PPRODR01_advanced_pay, "", "").Id; if (PAYTYP_id == Misc.Properties.DBs.SchoolQPaper.dbo.MST_PayType.Records.Cheque) { DS_Receipt_Obj.ChequeInfo.AddChequeInfoRow(PayTypes_Id, PPRODR01_cheque_no, DateTime.Now); } else if (PAYTYP_id == Misc.Properties.DBs.SchoolQPaper.dbo.MST_PayType.Records.MO) { DS_Receipt_Obj.MoneyOrderInfo.AddMoneyOrderInfoRow(PayTypes_Id, DateTime.Now, PPRODR01_cheque_no, PPRODR01_mo_office); } new Receipt.Receipt_Class().Save(entities, "", PPRODR01_datetime, PPRODR01_datetime, PPRODR01_advanced_pay, "", Settings.Default.CurrentFont, SCHL_id, null, DS_Receipt_Obj); } if (dispose) { trans.Commit(); } } catch (Exception ex) { if (dispose) { trans.Rollback(); } throw ex; } if (dispose) { trans.Dispose(); entities.Dispose(); } return(paperorder01_rec); }
public string SubmitClaim(PetClaimServiceViewModels model) { // Gets the selected filename... model.FileName = ApplicationSession.GlobalParameters.SelectedPetFileName; StringBuilder submitedfiles = new StringBuilder(); submitedfiles.Clear(); // Checks if file has been uploaded already, by checking the ApplicationSession.GlobalParameters.SelectedPetFileName value... if (!string.IsNullOrEmpty(model.FileName)) { // Starts connecting to the database... using (PetSureDatabaseEntities dbo = new PetSureDatabaseEntities()) { // Start the database transaction to ensure that the Entity Framework executes commands on the database within the context of that transaction... using (System.Data.Entity.DbContextTransaction transaction = dbo.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted)) { try { // Checks if the selected pet name is a valid petname... int petId = dbo.PetLists.Where(x => x.PetName == model.PetName).FirstOrDefault().PetId; int existCount = dbo.PetClaimServices.Where(x => x.PetId == petId).Count(); if (existCount > 0) { // Remove first all the existing records of the selected pet in PetClaimService table... dbo.PetClaimServices.RemoveRange(dbo.PetClaimServices.Where(x => x.PetId == petId)); // Saves all the changes made on the PetClaimService table... dbo.SaveChanges(); // Re-submit all the submitted new invoice file for the selected pet for pet claim... foreach (var item in ApplicationSession.GlobalParameters.PetClaimServiceList) { PetService.MVC.Models.PetClaimService petModel = new PetService.MVC.Models.PetClaimService(); petModel.PetId = petId; submitedfiles.Append(string.IsNullOrEmpty(submitedfiles.ToString())? petModel.FileName = item.FileName: String.Concat(", ", petModel.FileName = item.FileName)); petModel.FilePath = item.FilePath; petModel.PetClaimedDate = DateTime.Now; dbo.PetClaimServices.Add(petModel); dbo.SaveChanges(); } // Commits the underlying store transaction... transaction.Commit(); return(String.Format("Thank you for re-submitting ''{0}'' for {1}", submitedfiles.ToString(), model.PetName)); } else { // Submit all the submitted new invoice file for the selected pet for pet claim... foreach (var item in ApplicationSession.GlobalParameters.PetClaimServiceList) { PetService.MVC.Models.PetClaimService petModel = new PetService.MVC.Models.PetClaimService(); petModel.PetId = petId; submitedfiles.Append(string.IsNullOrEmpty(submitedfiles.ToString()) ? petModel.FileName = item.FileName : String.Concat(", ", petModel.FileName = item.FileName)); petModel.FilePath = item.FilePath; petModel.PetClaimedDate = DateTime.Now; dbo.PetClaimServices.Add(petModel); dbo.SaveChanges(); } // Commits the underlying store transaction... transaction.Commit(); return(String.Format("Thank you for submitting ''{0}'' for {1}", submitedfiles.ToString(), model.PetName)); } } catch (Exception) { // ROLLBACK TRANSACTION FOR ANY UNHANDLED EXCEPTION... transaction.Rollback(); } // CLEANS UP TRANSACTION OBJECT AND ENSURES THE ENTITY FRAMEWORK IS NO LONGER USING THAT TRANSACTION... transaction.Dispose(); } } } return("No Invoice Uploaded Yet!"); }
public bool UpdateWorkFlow(WorkFlow_Hdr ObjWorkFlow_HdrDL, List <WorkFlow_Dtls> ListWorkFlow_Dtls) { StackFrame stackFrame = new StackFrame(); MethodBase methodBase = stackFrame.GetMethod(); var strErrorMessage = string.Empty; // ObjWorkFlow_HdrDL.InsUser = "******"; // ObjCommTransHeaderDL.InsDate = DateTime.Now.ToString("dd/MM/yyyy"); bool result = true; using (System.Data.Entity.DbContextTransaction dbTran = objPharmaEntities.Database.BeginTransaction()) { try { if (objPharmaEntities.Database.Connection.State == System.Data.ConnectionState.Closed) { objPharmaEntities.Database.Connection.Open(); } WorkFlow_Hdr loclDtlsUpdate = (from objLinq in objPharmaEntities.WorkFlow_Hdr where objLinq.WorkFlow_Id == ObjWorkFlow_HdrDL.WorkFlow_Id select objLinq).FirstOrDefault(); if (loclDtlsUpdate != null) { loclDtlsUpdate.WorkFlow_Name = ObjWorkFlow_HdrDL.WorkFlow_Name; loclDtlsUpdate.WorkFlow_NameEn = ObjWorkFlow_HdrDL.WorkFlow_NameEn; loclDtlsUpdate.UpdateUser = ObjWorkFlow_HdrDL.UpdateUser; loclDtlsUpdate.UpdateDate = DateTime.Now; objPharmaEntities.SaveChanges(); } result = DeleteWorkFlow_Dtls(ObjWorkFlow_HdrDL.WorkFlow_Id); if (result) { foreach (WorkFlow_Dtls ObjWorkFlow_Dtls in ListWorkFlow_Dtls) { if (ObjWorkFlow_Dtls != null) { WorkFlow_Dtls loclWorkFlow_Dtls = new WorkFlow_Dtls { WorkFlow_Id = ObjWorkFlow_HdrDL.WorkFlow_Id, Job_Id = ObjWorkFlow_Dtls.Job_Id, WorkFlowOrder = ObjWorkFlow_Dtls.WorkFlowOrder }; objPharmaEntities.WorkFlow_Dtls.Add(loclWorkFlow_Dtls); //saves all above operations within one transaction objPharmaEntities.SaveChanges(); } } dbTran.Commit(); } //commit transaction } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); strErrorMessage = fullErrorMessage; // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); //((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors.First().ValidationErrors.First().ErrorMessage dbTran.Rollback(); result = false; } catch (Exception ex) { //Rollback transaction if exception occurs dbTran.Rollback(); result = false; } finally { objPharmaEntities.Database.Connection.Close(); dbTran.Dispose(); if (!string.IsNullOrEmpty(strErrorMessage)) { SaveErrorLog(System.Runtime.InteropServices.Marshal.GetExceptionCode().ToString(), strErrorMessage, this.UserNameProperty.ToString(), this.GetType().Name.ToString(), methodBase.Name.ToString()); } } return(result); } }