Example #1
0
        private Task ClearAsync()
        {
            var factory    = new DbProviderFactoriesSample();
            var expression = "DELETE FROM Names";
            var connection = factory.GetConnection();

            //var task = connection.OpenAsync();

            //using (var connection2 = factory.GetConnection())
            //{
            //    connection2.OpenAsync().ContinueWith(_ =>
            //     {
            //         var clearCommand = connection2.CreateCommand();
            //         clearCommand.CommandText = expression;
            //         clearCommand.ExecuteNonQuery();
            //     });
            //}

            return(connection.OpenAsync().ContinueWith(_ =>
            {
                var clearCommand = connection.CreateCommand();
                clearCommand.CommandText = expression;
                clearCommand.ExecuteNonQuery();
                connection.Close();
            }));
        }
Example #2
0
        private Task FillAsync(int iterations)
        {
            var factory    = new DbProviderFactoriesSample();
            var expression = "";

            var task = Task.Run(() =>
            {
                var insertRaw = "INSERT INTO Names(Name) VALUES('Vlad') ";
                expression    = "";

                for (int i = 0; i < iterations; i++)
                {
                    expression += insertRaw;
                }
            }).ContinueWith(t =>
            {
                var connection = factory.GetConnection();
                connection.OpenAsync().ContinueWith(_ =>
                {
                    var fillCommand         = connection.CreateCommand();
                    fillCommand.CommandText = expression;
                    fillCommand.ExecuteNonQuery();
                });
            });

            return(task);
        }
Example #3
0
        private Task ReadAsync(IList <NameViewModel> names)
        {
            var factory    = new DbProviderFactoriesSample();
            var expression = "SELECT * FROM Names";
            var connection = factory.GetConnection();

            return(connection.OpenAsync().ContinueWith(_ =>
            {
                var readCommand = connection.CreateCommand();
                readCommand.CommandText = expression;
                readCommand.ExecuteReaderAsync().ContinueWith(t =>
                {
                    while (t.Result.Read())
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            names.Add(new NameViewModel
                            {
                                Id = t.Result.GetInt32(0),
                                Name = t.Result.GetString(1)
                            });
                        });

                        //names.Add(new NameViewModel
                        //{
                        //    Id = t.Result.GetInt32(0),
                        //    Name = t.Result.GetString(1)
                        //});
                    }
                    connection.Close();
                }
                                                              );
            }));
        }
Example #4
0
        private void Clear()
        {
            var factory    = new DbProviderFactoriesSample();
            var expression = "DELETE FROM Names";

            using (var connection = factory.GetConnection())
            {
                connection.Open();
                var clearCommand = connection.CreateCommand();
                clearCommand.CommandText = expression;
                clearCommand.ExecuteNonQuery();
            }
        }
Example #5
0
        private void Read()
        {
            var factory    = new DbProviderFactoriesSample();
            var expression = "SELECT * FROM Names";

            using (var connection = factory.GetConnection())
            {
                connection.Open();
                var readCommand = connection.CreateCommand();
                readCommand.CommandText = expression;
                var reader = readCommand.ExecuteReader();
                while (reader.Read())
                {
                    Console.WriteLine($"ID: {reader.GetInt32(0)}\tName: {reader.GetString(1)}");
                }
            }
        }
Example #6
0
        private void Fill(int iterations)
        {
            var factory    = new DbProviderFactoriesSample();
            var insertRaw  = "INSERT INTO Names(Name) VALUES('Vlad') ";
            var expression = "";

            for (int i = 0; i < iterations; i++)
            {
                expression += insertRaw;
            }

            using (var connection = factory.GetConnection())
            {
                connection.Open();
                var fillCommand = connection.CreateCommand();
                fillCommand.CommandText = expression;
                fillCommand.ExecuteNonQuery();
            }
        }
Example #7
0
        private void Read(IList <NameViewModel> names)
        {
            var factory    = new DbProviderFactoriesSample();
            var expression = "SELECT * FROM Names";

            using (var connection = factory.GetConnection())
            {
                connection.Open();
                var readCommand = connection.CreateCommand();
                readCommand.CommandText = expression;
                var reader = readCommand.ExecuteReader();
                while (reader.Read())
                {
                    names.Add(new NameViewModel
                    {
                        Id   = reader.GetInt32(0),
                        Name = reader.GetString(1)
                    });
                }
            }
        }
Example #8
0
        private Task ReadAsync()
        {
            var factory    = new DbProviderFactoriesSample();
            var expression = "SELECT * FROM Names";
            var connection = factory.GetConnection();

            return(connection.OpenAsync().ContinueWith(_ =>
            {
                completed = true;
                var readCommand = connection.CreateCommand();
                readCommand.CommandText = expression;
                readCommand.ExecuteReaderAsync().ContinueWith(t =>
                {
                    while (t.Result.Read())
                    {
                        Console.WriteLine($"ID: {t.Result.GetInt32(0)}\tName: {t.Result.GetString(1)}");
                    }
                    connection.Close();
                }
                                                              );
            }));
        }