private bool CommitTransaction(System.Data.Entity.Core.Objects.SaveOptions saveOptions, DbTransaction transaction, EFDbContext dbContext) { bool result = false; if (transaction == null) { throw new ApplicationException("Cannot commit a transaction while there is no transaction running."); } try { if (dbContext.ChangeTracker.Entries().Any(x => x.State != System.Data.Entity.EntityState.Detached && x.State != System.Data.Entity.EntityState.Unchanged)) { try { if (BeforeSave != null) { List <object> para = new List <object>(); para.Add(this.UserID); para.Add(dbContext); BeforeSave(para); } System.Data.Entity.Core.Objects.ObjectContext objContext = dbContext.ObjectContext; objContext.SaveChanges(saveOptions); } catch (Exception exp) { if (SaveException != null) { SaveException(exp); } else { throw exp; } } } transaction.Commit(); result = true; } catch (Exception exp) { throw exp; } finally { ReleaseCurrentTransaction(transaction); } return(result); }
private bool CommitTransaction(bool b, System.Data.Entity.Core.Objects.SaveOptions saveOptions, DbTransaction transaction, EFDbContext dbContext) { bool result = false; if (transaction == null) { throw new ApplicationException("Cannot commit a transaction while there is no transaction running."); } if (!b) { transaction.Rollback(); } else { try { System.Data.Entity.Core.Objects.ObjectContext objContext = ((IObjectContextAdapter)dbContext).ObjectContext; objContext.SaveChanges(saveOptions); dbContext.SaveChanges(); transaction.Commit(); result = true; } catch (Exception exp) { } finally { ReleaseCurrentTransaction(transaction); } } ReleaseCurrentTransaction(transaction); return(result); }
public EFDALContainer(DatabaseInfo DbInfo) { _DbContext = new EFDbContext(DbInfo.Name); }