public async Task SaveAsync(IEnumerable <FileInfoDto> newDtoFiles) { var categories = await GetOrCreateCategoriesFor(newDtoFiles); var newFiles = newDtoFiles.Select(dto => { var withCategory = categories.Single(c => c.Name == dto.Category); return(FileInfo.From(dto, withCategory)); }).ToList(); await MakeIndexesUniqueFor(newFiles); await db.Files.SaveAsync(newFiles); await db.CommitChangesAsync(); }