Example #1
0
        public async Task PersistWorkItemsAsync(IEnumerable <WorkItem> items)
        {
            var ids = items.Select(wi => wi.Id).ToArray();

            var existingItems = await this.ListAsync(new WorkItemFilterForExistingItems(ids));

            var comparer = new WorkItemComparer();

            // updates
            var updates = items.Intersect(existingItems, comparer);

            this.DbContext.WorkItems.UpdateRange(updates);

            // new items
            var inserts = items.Except(existingItems, comparer);

            this.DbContext.WorkItems.AddRange(inserts);

            await this.DbContext.SaveChangesAsync();
        }
        public async Task PersistWorkItemsAsync(IEnumerable <WorkItem> items)
        {
            var ids           = items.Select(wi => wi.Id).ToArray();
            var existingItems = await _context.WorkItems
                                .Where(wi => ids.Contains(wi.Id))
                                .ToListAsync <WorkItem>();

            var comparer = new WorkItemComparer();

            // updates
            var updates = items.Intersect(existingItems, comparer);

            _context.WorkItems.UpdateRange(updates);

            // new items
            var inserts = items.Except(existingItems, comparer);

            _context.WorkItems.AddRange(inserts);

            await _context.SaveChangesAsync();
        }