public async Task UpdatesNpgSql()
        {
            var toUpdate = NpgSqlIds.Take(2)
                           .ToDictionary(key => key, value => DateTime.UtcNow.AddDays(value + 1));

            using (var db = new postgresContext())
            {
                var result = await db.Efcoretest.BulkUpdateAsync(toUpdate.Select(x => x.Key), id => new Efcoretest
                {
                    Modifieddate = toUpdate[id]
                });

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

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

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

                foreach (var u in updated)
                {
                    Assert.Contains(u.Id, toUpdate.Select(x => x.Key));

                    var expected = toUpdate[u.Id];
                    var actual   = u.Modifieddate;

                    Assert.Equal(expected.ToString("d"), actual.ToString("d"));
                }
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        public async Task JoinsByPrimaryKeyNpgSql()
        {
            var expectedIds = NpgSqlIds.Take(5).ToList();

            List <int> actualIds;

            using (var db = new postgresContext())
            {
                actualIds = await db.Efcoretest
                            .Join(expectedIds)
                            .Select(e => e.Id)
                            .ToListAsync();
            }

            Assert.Equal(expectedIds.Count, actualIds.Count);

            foreach (var expected in expectedIds)
            {
                Assert.Contains(expected, actualIds);
            }
        }
        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"));
                }
            }
        }