Как я могу заполнить таблицы ?, это консольная прикладная программа c# - PullRequest
0 голосов
/ 22 апреля 2020

Как мне заполнить таблицы здесь? и как мне активировать Марс, так как у меня нет подключения к строке? хотя в конфиге приложения. Я пробовал разные способы заполнения, но на данный момент ничего не работает, и я не вижу, чтобы найти хороший пример из-за формата кода

public async Task<IList<Table>> GetTargetTables()
        {
            using var dbConnection = dbConfig.GenerateConnection(shouldOpen: true);

          var allTablesInSchema = await dbConnection
                .ExecuteAndReadResultsAsync(
                    queryForAllTables, r => r.GetString(0),
                    furtherSetup: (SqlCommand sqlCommand) => sqlCommand.Parameters.AddWithValue("@targetSchema", schemaName)) 
                .ConfigureAwait(false);

            var timeSeriesTablesInSchema = await dbConnection
                .ExecuteAndReadResultsAsync(
                    queryForTimeSeriesTables, r => r.GetString(0),
                    furtherSetup: (SqlCommand sqlCommand) => sqlCommand.Parameters.AddWithValue("@targetSchema", schemaName)) 
                .ContinueWith(c => c.Result.AsHashSet())
                .ConfigureAwait(false);

            return allTablesInSchema
                .Select(tableName => new Table
                {
                    Name = tableName,
                    IsTimeSeries = timeSeriesTablesInSchema.Contains(tableName)
                })
                .ToList();
        }

        public async Task Run()
        {

            var tablesWeSeek = await GetTargetTables().ConfigureAwait(false);
            var readings = new ConcurrentBag<CombinedReading>();

            if (tablesWeSeek.None())
            {
                LogTo.Warn("Didn't find tables to inspect");
                return;
            }

            Parallel.ForEach(tablesWeSeek, new ParallelOptions { MaxDegreeOfParallelism = maxConcurrentQueries }, table =>
            {
                var timeSubQuery = !table.IsTimeSeries ? "convert(varchar(100), null), convert(date, null), convert(bit, 0)" : $@"'{HardcodedNameOfTimestampColumn}',
                                (
                                    select top 1 [{HardcodedNameOfTimestampColumn}]
                                    from [{schemaName}].[{table.Name}]
                                    order by [{HardcodedNameOfTimestampColumn}] desc
                                ), convert(bit, 1)";
                var query = $@"
                        select '{table.Name}', count_big(*),
                                convert(date, GetDate()), {timeSubQuery}
                        from [{schemaName}].[{table.Name}]";


Here im suppose to activate Mars but i have no idea how, i do have the string in app config but how do i utilize here?


                // For this to work make sure to enable MultipleActiveResultSets

                using var dbConnection = dbConfig.GenerateConnection(shouldOpen: true);
                dbConnection.ExecuteAndReadResultsAsync(query, CombinedReadingConverter)
                    .ContinueWith(task => readings.AddAll(task.Result))
                    .Wait();
            });

            if (tablesWeSeek.Count != readings.Count)
                LogTo.Warn($"We have an issue since the number of readings ({readings.Count}) does not match our table count (${tablesWeSeek.Count})");

Я предполагаю заполнить здесь таблицы

данные одной таблицы

public sealed class TableReading
    {
        public string TableName { get; set; }
        public DateTime InspectedOn { get; set; }
        public int RecordCount { get; set; }
    }

...