コード例 #1
0
 /// <summary>
 /// Saves all changes made in this context to the database.
 /// </summary>
 /// <returns>The number of state entries written to the database.</returns>
 public virtual int SaveChanges()
 {
     try
     {
         _context.Audit();
         return(_context.SaveChanges());
     }
     catch (DbUpdateException exception)
     {
         string errorText = _context.RollbackEntityChanges(exception);
         throw new Exception(errorText, exception);
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
コード例 #2
0
        public DbContextOptions <T> DatabaseOptionsWithData <T>(string databaseName, Type contextType) where T : DbContext, IDbContext
        {
            DbContextOptions <T> options = DatabaseOptions <T>(databaseName);

            List <FakeEntity> fakeEntities = new FakeEntities();

            using (IDbContext context = Activator.CreateInstance(contextType, new object[] { options }) as IDbContext)
            {
                context.Set <FakeEntity>().AddRange(fakeEntities);
                context.Audit();
                context.SaveChanges();
            }

            return(options);
        }