예제 #1
0
        public async Task <PersonContext> CreatePersonContextWithPeople(params Person[] people)
        {
            PersonContext context = CreatePersonContext();

            foreach (Person person in people)
            {
                await context.AddAsync(person);
            }

            await context.SaveChangesAsync();

            return(context);
        }
예제 #2
0
        public async Task <TEntity> AddAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                await _myDBContext.AddAsync(entity);

                await _myDBContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception)
            {
                throw new Exception($"{nameof(entity)} could not be saved");
            }
        }