Esempio n. 1
0
        public void DefaultValuesInsert()
        {
            if (!EnsureVersion(new Version(3, 0, 0, 0)))
            {
                return;
            }

            using (var db = GetDbContext <DefaultValuesInsertContext>())
            {
                db.Database.ExecuteSqlRaw("create table test_insert_devaultvalues (id int generated by default as identity (start with 26) primary key, name generated always as (id || 'foobar'))");
                var entity = new DefaultValuesInsertEntity()
                {
                };
                db.Add(entity);
                db.SaveChanges();
                Assert.AreEqual(27, entity.Id);
                Assert.AreEqual("27foobar", entity.Name);
            }
        }
Esempio n. 2
0
        public async Task DefaultValuesInsert()
        {
            if (!await EnsureVersion(new Version(3, 0, 0, 0)))
            {
                return;
            }

            var id = await GetServerVersion() >= new Version(4, 0, 0, 0) ? 26 : 27;

            await using (var db = await GetDbContext <DefaultValuesInsertContext>())
            {
                await db.Database.ExecuteSqlRawAsync("create table test_insert_devaultvalues (id int generated by default as identity (start with 26) primary key, name generated always as (id || 'foobar'))");

                var entity = new DefaultValuesInsertEntity()
                {
                };
                await db.AddAsync(entity);

                await db.SaveChangesAsync();

                Assert.AreEqual(id, entity.Id);
                Assert.AreEqual($"{id}foobar", entity.Name);
            }
        }