コード例 #1
0
        public override async Task UpgradeAsync(DbTransaction?transaction = null, CancellationToken token = default)
        {
            var tempContextOptionsBuilder = new DbContextOptionsBuilder <TempContext>();

            tempContextOptionsBuilder.UseNpgsql(DbProvider.Connection);

            var anotherTempContextOptionsBuilder = new DbContextOptionsBuilder <AnotherTempContext>();

            anotherTempContextOptionsBuilder.UseNpgsql(DbProvider.Connection);

            using (var tempContext = new TempContext(tempContextOptionsBuilder.Options))
                using (var anotherContext = new AnotherTempContext(anotherTempContextOptionsBuilder.Options))
                {
                    // tempContext.Database.UseTransaction(transaction);
                    // anotherContext.Database.UseTransaction(transaction);

                    var request1 = new BackgroundProcessorRequestEntity
                    {
                        CreatedUtc         = DateTime.Now,
                        TimeZoneId         = "temo",
                        Type               = 1,
                        State              = 1,
                        UserId             = 1,
                        ProjectId          = 1,
                        RequestCultureName = "ru"
                    };
                    var request2 = new BackgroundProcessorRequestEntity
                    {
                        CreatedUtc         = DateTime.Now,
                        TimeZoneId         = "temo",
                        Type               = 1,
                        State              = 1,
                        UserId             = 1,
                        ProjectId          = 1,
                        RequestCultureName = "ru"
                    };

                    tempContext.Requests.Add(request1);
                    anotherContext.Requests.Add(request2);

                    await tempContext.SaveChangesAsync();

                    await anotherContext.SaveChangesAsync();
                }
        }
コード例 #2
0
        public async Task Create(TEntity entity)
        {
            await _dbContext.Set <TEntity>().AddAsync(entity);

            await _dbContext.SaveChangesAsync();
        }