Beispiel #1
0
        public async Task <bool> UpdateSequenceAsync <T>(string name, DbSequenceUpdate <T> update, CancellationToken ct = default)
            where T : struct
        {
            var connection = this.context.Database.GetDbConnection();

            if (connection.State != ConnectionState.Open)
            {
                await connection.OpenAsync(ct);
            }

            var restart   = update.RestartWith != null ? $"RESTART WITH {update.RestartWith}" : "";
            var increment = update.IncrementBy != null ? $"INCREMENT BY {update.IncrementBy}" : "";
            var min       = update.MinValue != null ? $"MINVALUE {update.MinValue}" : "";
            var max       = update.MaxValue != null ? $"MAXVALUE {update.MaxValue}" : "";
            var cycle     = update.Cycle != null ? (update.Cycle.Value ? "CYCLE" : "NO CYCLE") : "";
            var cache     = update.CacheSize != null ? (update.CacheSize.Value > 0 ? $"CACHE {update.CacheSize}" : "NO CACHE") : "";

            var sql =
                $"ALTER SEQUENCE {name} " +
                $"{restart} " +
                $"{increment}" +
                $"{min} " +
                $"{max}" +
                $"{cycle}" +
                $"{cache}";

            var result = await this.context.Database.ExecuteSqlRawAsync(sql, ct);

            return(result == -1);
        }
        public async Task <IActionResult> UpdateSequence([FromRoute] string name, [FromBody] DbSequenceUpdate <long> update)
        {
            var res = await this.context.UpdateSequenceAsync(name, update, this.HttpContext.RequestAborted);

            return(this.Ok());
        }