Esempio n. 1
0
        private async Task <SqlServerModel> BuildFromAttribute(
            SqlServerAttribute attribute,
            CancellationToken cancellationToken)
        {
            using (var connection = new SqlConnection(attribute.ConnectionString))
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = attribute.Query;

                    var reader = await command.ExecuteReaderAsync(cancellationToken);

                    var names = Enumerable.Range(0, reader.FieldCount).Select(reader.GetName).ToList();
                    while (await reader.ReadAsync(cancellationToken))
                    {
                        var expando = new ExpandoObject() as IDictionary <string, object>;
                        foreach (var name in names)
                        {
                            expando[name] = reader[name];
                        }
                        return(new SqlServerModel
                        {
                            Record = expando
                        });
                    }

                    return(new SqlServerModel());
                }
            }
        }
 public SqlAsyncCollector(SqlServerAttribute attribute)
 {
     this.attribute = attribute;
 }