Пример #1
0
        public async Task BulkUpsertAsync(IEnumerable <TEntity> entity)
        {
            try
            {
                if (entity != null && entity.Any())
                {
                    unitOfWork.SetAutoDetectChanges(true);

                    foreach (TEntity item in entity)
                    {
                        await unitOfWork.GetSet <TEntity, TId>().AddAsync(item);

                        //if (item.Id > 0 && unitOfWork.GetSet<TEntity, TId>().Any(info =>
                        //        info.Id == item.Id))
                        //{
                        //    unitOfWork.GetSet<TEntity, TId>().Update(item);
                        //}
                        //else
                        //{
                        //    await unitOfWork.GetSet<TEntity, TId>().AddAsync(item);
                        //}
                    }

                    await unitOfWork.CommitAsync();
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                //unitOfWork.SetAutoDetectChanges(true);
            }
        }