コード例 #1
0
 public async Task Create(ToDoItem item)
 {
     using (var _db = _contextFactory.CreateContext())
     {
         _db.Items.Add(item);
         int rowsAffected = await _db.SaveChangesAsync().ConfigureAwait(false);
     }
 }
コード例 #2
0
        public async Task <List <ToDoItem> > GetIncompleteItems(
            Guid userId,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var _db = _contextFactory.CreateContext())
            {
                var query = _db.Items
                            .Where(x =>
                                   x.UserId == userId &&
                                   x.IsComplete == false
                                   )
                            .OrderBy(x => x.CreatedUtc)
                ;

                return(await query.AsNoTracking().ToListAsync <ToDoItem>(cancellationToken).ConfigureAwait(false));
            }
        }