示例#1
0
        public async Task RemovesNpgSql()
        {
            var toDelete = NpgSqlIds.Skip(5).Take(5).ToList();

            using (var db = new postgresContext())
            {
                var entities = await db.Efcoretest
                               .Where(e => toDelete.Contains(e.Id))
                               .ToListAsync();

                Assert.NotEmpty(entities);
            }

            using (var db = new postgresContext())
            {
                var result = await db.Efcoretest
                             .Where(e => e.Name.Contains(nameof(BulkRemoveTests)))
                             .BulkRemoveAsync(toDelete);

                Assert.Equal(5, result);
            }

            using (var db = new postgresContext())
            {
                var entities = await db.Efcoretest
                               .Where(e => toDelete.Contains(e.Id))
                               .ToListAsync();

                Assert.Empty(entities);
            }
        }
        public async Task UpdatesWithoutKeysNpgSql()
        {
            var createdDate = DateTime.Parse(DateTime.UtcNow.AddDays(1).Date.ToString("d"));

            var toUpdate = NpgSqlIds.Skip(2).Take(2).ToList();

            using (var db = new postgresContext())
            {
                var result = await db.Efcoretest
                             .Where(x => toUpdate.Contains(x.Id))
                             .BulkUpdateAsync(() => new Efcoretest
                {
                    Createddate = createdDate
                });

                Assert.Equal(toUpdate.Count, result);
            }

            using (var db = new postgresContext())
            {
                var updated = await db.Efcoretest
                              .Where(x => toUpdate.Contains(x.Id))
                              .ToListAsync();

                Assert.Equal(toUpdate.Count, updated.Count);

                foreach (var u in updated)
                {
                    Assert.Contains(u.Id, toUpdate);

                    var expected = createdDate;
                    var actual   = u.Createddate.ToUniversalTime();

                    Assert.Equal(expected.ToString("d"), actual.ToString("d"));
                }
            }
        }