Ejemplo n.º 1
0
        public static async Task SaveAll <T>(this IEnumerable <T> objects, RepositoryContext context) where T : Entity.IEntity
        {
            var list = objects.ToList();

            if (!list.Any())
            {
                return;
            }

            using (var transaction = context.OpenTransaction())
            {
                try
                {
                    foreach (var o in list)
                    {
                        await context.AddToTransaction(o).ConfigureAwait(false);
                    }
                    await transaction.CommitAsync().ConfigureAwait(false);
                }
                catch (System.Exception)
                {
                    await transaction.RollbackAsync().ConfigureAwait(false);

                    throw;
                }
            }
        }