当前位置: 首页>>代码示例>>C#>>正文


C# NpgsqlCommand.ExecuteReaderAsync方法代码示例

本文整理汇总了C#中Npgsql.NpgsqlCommand.ExecuteReaderAsync方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlCommand.ExecuteReaderAsync方法的具体用法?C# NpgsqlCommand.ExecuteReaderAsync怎么用?C# NpgsqlCommand.ExecuteReaderAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Npgsql.NpgsqlCommand的用法示例。


在下文中一共展示了NpgsqlCommand.ExecuteReaderAsync方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Reader

 public async void Reader()
 {
     using (var cmd = new NpgsqlCommand("SELECT 1", Conn))
     using (var reader = await cmd.ExecuteReaderAsync())
     {
         await reader.ReadAsync();
         Assert.That(reader[0], Is.EqualTo(1));
     }
 }
开发者ID:Emill,项目名称:Npgsql,代码行数:9,代码来源:AsyncTests.cs

示例2: Columnar

 public async void Columnar()
 {
     using (var cmd = new NpgsqlCommand("SELECT NULL, 2, 'Some Text'", Conn))
     using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess))
     {
         await reader.ReadAsync();
         Assert.That(await reader.IsDBNullAsync(0), Is.True);
         Assert.That(await reader.GetFieldValueAsync<string>(2), Is.EqualTo("Some Text"));
     }
 }
开发者ID:Emill,项目名称:Npgsql,代码行数:10,代码来源:AsyncTests.cs

示例3: Columnar

 public async void Columnar()
 {
     ExecuteNonQuery("INSERT INTO DATA (field_int4, field_text) VALUES (2, 'Some Text')");
     using (var cmd = new NpgsqlCommand("SELECT field_int2, field_int4, field_text FROM data", Conn))
     using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess))
     {
         await reader.ReadAsync();
         Assert.That(await reader.IsDBNullAsync(0), Is.True);
         Assert.That(await reader.GetFieldValueAsync<string>(2), Is.EqualTo("Some Text"));
     }
 }
开发者ID:roji,项目名称:Npgsql,代码行数:11,代码来源:AsyncTests.cs

示例4: buildEventPage

        private async Task<EventPage> buildEventPage(long lastEncountered, NpgsqlCommand cmd)
        {
            IList<IEvent> events = null;
            IList<long> sequences = new List<long>();

            using (var reader = await cmd.ExecuteReaderAsync(_token).ConfigureAwait(false))
            {
                while (await reader.ReadAsync(_token).ConfigureAwait(false))
                {
                    var seq = await reader.GetFieldValueAsync<long>(0, _token).ConfigureAwait(false);
                    sequences.Add(seq);
                }

                if (sequences.Any())
                {
                    await reader.NextResultAsync(_token).ConfigureAwait(false);

                    events = await _selector.ReadAsync(reader, _map, _token).ConfigureAwait(false);
                }
                else
                {
                    events = new List<IEvent>();
                }
            }

            return new EventPage(lastEncountered, sequences, events) {Count = events.Count};
        }
开发者ID:phillip-haydon,项目名称:marten,代码行数:27,代码来源:Fetcher.cs

示例5: ExecuteReaderAsync

 public async void ExecuteReaderAsync(int rows)
 {
     for (var i = 0; i < rows; i++)
         ExecuteNonQuery("INSERT INTO DATA (field_int4) VALUES (10)");
     using (var metrics = TestMetrics.Start(TestRunTime, true))
     {
         while (!metrics.TimesUp)
         {
             using (var cmd = new NpgsqlCommand("SELECT field_int4 FROM data", Conn))
             using (var reader = await cmd.ExecuteReaderAsync())
             {
                 while (await reader.ReadAsync()) { }
             }
             metrics.IncrementIterations();
         }
     }
 }
开发者ID:Tradioyes,项目名称:Npgsql,代码行数:17,代码来源:SpeedTests.cs

示例6: GetDriverByLastNameAsync

		public async Task<IEnumerable<Driver>> GetDriverByLastNameAsync(string theDriverName)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aPreparedCommand =
					new NpgsqlCommand(
						"SELECT id, firstname, lastname, address, city, state, postalcode, country, licensenumber, licensestate, customerid from driver where id = :value1", Connection);
				var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Text) { Value = theDriverName };
				aPreparedCommand.Parameters.Add(aParam);

				var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);

				if (!aReader.HasRows)
					return null;

				var aReturn = new List<Driver>();
				while (await aReader.ReadAsync().ConfigureAwait(false))
				{
					aReturn.Add(ReadDriver(aReader));
				}
				return aReturn;
			}
			catch (NpgsqlException)
			{
				return null;
			}
			catch (InvalidOperationException)
			{
				return null;
			}
			catch (SqlException)
			{
				return null;
			}
			catch (ConfigurationErrorsException)
			{
				return null;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
开发者ID:gblosser,项目名称:FullStackReference,代码行数:46,代码来源:DriverRepository.cs

示例7: GetCustomerByNameAsync

		public async Task<Customer> GetCustomerByNameAsync(string theCustomerName)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aPreparedCommand =
					new NpgsqlCommand(
						"SELECT id, name, allowsadditionaldrivers, allowsadditions, hasmaxrentaldays, maxrentaldays from customer where name = :value1", Connection);
				var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Text) { Value = theCustomerName };
				aPreparedCommand.Parameters.Add(aParam);

				var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);

				if (!aReader.HasRows)
					return null;

				var aReturn = new Customer();
				while (await aReader.ReadAsync().ConfigureAwait(false))
				{
					aReturn = ReadCustomer(aReader);
				}
				return aReturn;
			}
			catch (NpgsqlException)
			{
				return null;
			}
			catch (InvalidOperationException)
			{
				return null;
			}
			catch (SqlException)
			{
				return null;
			}
			catch (ConfigurationErrorsException)
			{
				return null;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
开发者ID:gblosser,项目名称:FullStackReference,代码行数:46,代码来源:CustomerRepository.cs

示例8: buildEventPage

        private async Task<EventPage> buildEventPage(long @from, NpgsqlCommand cmd)
        {
            IList<IEvent> events = null;
            IList<long> sequences = new List<long>();

            long nextKnown = 0;
            long lastKnown = 0;

            using (var reader = await cmd.ExecuteReaderAsync(_token).ConfigureAwait(false))
            {
                while (await reader.ReadAsync(_token).ConfigureAwait(false))
                {
                    var seq = await reader.GetFieldValueAsync<long>(0, _token).ConfigureAwait(false);
                    sequences.Add(seq);
                }

                if (sequences.Any())
                {
                    await reader.NextResultAsync(_token).ConfigureAwait(false);

                    events = await _selector.ReadAsync(reader, _map, null, _token).ConfigureAwait(false);
                }
                else
                {
                    events = new List<IEvent>();
                }

                nextKnown = await getLong(reader).ConfigureAwait(false);
                lastKnown = await getLong(reader).ConfigureAwait(false);
            }

            return new EventPage(@from, sequences, events)
            {
                Count = events.Count,
                NextKnownSequence = nextKnown,
                LastKnownSequence = lastKnown
            };
        }
开发者ID:JasperFx,项目名称:marten,代码行数:38,代码来源:Fetcher.cs

示例9: GetLocationsForCustomerAsync

		public async Task<IEnumerable<Location>> GetLocationsForCustomerAsync(int theCustomerId)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aPreparedCommand = new NpgsqlCommand("SELECT id, customerid, name, address, city, state, postalcode, country, latitude, longitude  from location where customerid=:value1", Connection);
				aPreparedCommand.Parameters.AddWithValue("value1", theCustomerId);

				var aReader = await aPreparedCommand.ExecuteReaderAsync();

				if (!aReader.HasRows)
					return Enumerable.Empty<Location>();

				var aReturn = new List<Location>();
				while (await aReader.ReadAsync().ConfigureAwait(false))
				{
					aReturn.Add(ReadLocation(aReader));
				}
				return aReturn;
			}
			catch (NpgsqlException)
			{
				return Enumerable.Empty<Location>();
			}
			catch (InvalidOperationException ex)
			{
				return Enumerable.Empty<Location>();
			}
			catch (SqlException)
			{
				return Enumerable.Empty<Location>();
			}
			catch (ConfigurationErrorsException)
			{
				return Enumerable.Empty<Location>();
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
开发者ID:gblosser,项目名称:FullStackReference,代码行数:43,代码来源:LocationRepository.cs

示例10: GetLocationAsync

		public async Task<Location> GetLocationAsync(int theLocationId)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aPreparedCommand =
					new NpgsqlCommand(
						"SELECT id, customerid, name, address, city, state, postalcode, country, latitude, longitude from location where id = :value1", Connection);
				var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Integer) { Value = theLocationId };
				aPreparedCommand.Parameters.Add(aParam);

				var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);

				if (!aReader.HasRows)
					return null;

				var aReturn = new Location();
				while (await aReader.ReadAsync().ConfigureAwait(false))
				{
					aReturn = ReadLocation(aReader);
				}
				return aReturn;
			}
			catch (NpgsqlException)
			{
				return null;
			}
			catch (InvalidOperationException)
			{
				return null;
			}
			catch (SqlException)
			{
				return null;
			}
			catch (ConfigurationErrorsException)
			{
				return null;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
开发者ID:gblosser,项目名称:FullStackReference,代码行数:46,代码来源:LocationRepository.cs

示例11: executeCallbacksAsync

        private static async Task executeCallbacksAsync(NpgsqlCommand cmd, CancellationToken tkn, BatchCommand batch, List<Exception> list)
        {
            using (var reader = await cmd.ExecuteReaderAsync(tkn).ConfigureAwait(false))
            {
                if (batch.Callbacks.Any())
                {
                    if (batch.Callbacks[0] != null)
                    {
                        await batch.Callbacks[0].PostprocessAsync(reader, list, tkn).ConfigureAwait(false);
                    }

                    for (int i = 1; i < batch.Callbacks.Count; i++)
                    {
                        await reader.NextResultAsync(tkn).ConfigureAwait(false);

                        if (batch.Callbacks[i] != null)
                        {
                            await batch.Callbacks[i].PostprocessAsync(reader, list, tkn).ConfigureAwait(false);
                        }
                    }
                }
            }
        }
开发者ID:danielmarbach,项目名称:marten,代码行数:23,代码来源:UpdateBatch.cs

示例12: GetUserByEmailAsync

		public async Task<User> GetUserByEmailAsync(string theEmail)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aPreparedCommand =
					new NpgsqlCommand(
						"SELECT id, firstname, lastname, email, customerid, isemployee from appuser where email = :value1", Connection);
				var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Text) { Value = theEmail };
				aPreparedCommand.Parameters.Add(aParam);

				var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);

				if (!aReader.HasRows)
					return null;

				var aReturn = new User();
				while (await aReader.ReadAsync().ConfigureAwait(false))
				{
					aReturn = ReadUser(aReader);
				}
				return aReturn;
			}
			catch (NpgsqlException)
			{
				return null;
			}
			catch (InvalidOperationException)
			{
				return null;
			}
			catch (SqlException)
			{
				return null;
			}
			catch (ConfigurationErrorsException)
			{
				return null;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
开发者ID:gblosser,项目名称:FullStackReference,代码行数:46,代码来源:UserRepository.cs

示例13: GetAutomobilesAsync

		public async Task<IEnumerable<Automobile>> GetAutomobilesAsync(IEnumerable<int> theAutomobileIds)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aPreparedCommand =
					new NpgsqlCommand(
						"SELECT id, vin, vehiclenumber, name, class, style, color, manufacturer, model, code, locationid from automobile where id = :value1", Connection);
				aPreparedCommand.Parameters.AddWithValue("value1", string.Join(",", theAutomobileIds));

				var aReader = await aPreparedCommand.ExecuteReaderAsync();

				if (!aReader.HasRows)
					return Enumerable.Empty<Automobile>().ToList();

				var aReturnList = new List<Automobile>();
				while (await aReader.ReadAsync())
				{
					aReturnList.Add(ReadAutomobile(aReader));
				}
				return aReturnList;
			}
			catch (NpgsqlException)
			{
				return Enumerable.Empty<Automobile>().ToList();
			}
			catch (InvalidOperationException)
			{
				return Enumerable.Empty<Automobile>().ToList();
			}
			catch (SqlException)
			{
				return Enumerable.Empty<Automobile>().ToList();
			}
			catch (ConfigurationErrorsException)
			{
				return Enumerable.Empty<Automobile>().ToList();
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
开发者ID:gblosser,项目名称:FullStackReference,代码行数:45,代码来源:AutomobileRepository.cs

示例14: GetAutomobileAsync

		public async Task<Automobile> GetAutomobileAsync(int theAutomobileId)
		{
			try
			{
				await Connection.OpenAsync().ConfigureAwait(false);

				var aPreparedCommand =
					new NpgsqlCommand(
						"SELECT id, vin, vehiclenumber, name, class, style, color, manufacturer, model, code, locationid from automobile where id = :value1", Connection);
				var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Integer) { Value = theAutomobileId };
				aPreparedCommand.Parameters.Add(aParam);

				var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);

				if (!aReader.HasRows)
					return null;

				var aReturn = new Automobile();
				while (await aReader.ReadAsync().ConfigureAwait(false))
				{
					aReturn = ReadAutomobile(aReader);
				}
				return aReturn;
			}
			catch (NpgsqlException)
			{
				return null;
			}
			catch (InvalidOperationException)
			{
				return null;
			}
			catch (SqlException)
			{
				return null;
			}
			catch (ConfigurationErrorsException)
			{
				return null;
			}
			finally
			{
				if (Connection.State == ConnectionState.Open)
					Connection.Close();
			}
		}
开发者ID:gblosser,项目名称:FullStackReference,代码行数:46,代码来源:AutomobileRepository.cs


注:本文中的Npgsql.NpgsqlCommand.ExecuteReaderAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。