Example #1
0
        internal static ThingDbContext CreateDbContext()
        {
            var dbContext = new ThingDbContext();

            dbContext.Database.Log = Console.WriteLine;
            return(dbContext);
        }
Example #2
0
        internal static void Persist(Action <ThingDbContext> action)
        {
            using (var dbContext = new ThingDbContext())
            {
                dbContext.Database.Log = Console.WriteLine;

                var tx = dbContext.Database.BeginTransaction();

                try
                {
                    action(dbContext);
                    dbContext.SaveChanges();
                    tx.Commit();
                }
                catch (Exception)
                {
                    tx.Rollback();
                    throw;
                }
            }
        }