public void InsertProductEFSP()
        {
            string connectionString        = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            EntityFrameworkCoreData efData = new(connectionString);
            SqlCommandModel         model  = new()
            {
                CommandText       = "EXEC InsertProduct @ProductName = {0}, @CategoryID = {1}, @SupplierID = {2}, @Discontinued = {3}",
                CommandType       = CommandType.StoredProcedure,
                CommandParameters = new SqlCommandParameterModel[] {
                    new SqlCommandParameterModel()
                    {
                        ParameterName = "@ProductName", DataType = DbType.String, Value = "Dapper Product Edited"
                    }
                    , new SqlCommandParameterModel()
                    {
                        ParameterName = "@CategoryID", DataType = DbType.Int32, Value = 1
                    }
                    , new SqlCommandParameterModel()
                    {
                        ParameterName = "@SupplierID", DataType = DbType.Int32, Value = 1
                    }
                    , new SqlCommandParameterModel()
                    {
                        ParameterName = "@Discontinued", DataType = DbType.Boolean, Value = false
                    }
                }
            };

            efData.ExecuteNonQuerySP(model);
            efData.Dispose();
        }
        public void InsertProductDDNSP()
        {
            string          connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            DapperDotNet    ddnData          = new(connectionString);
            SqlCommandModel model            = new()
            {
                CommandText       = "InsertProduct",
                CommandType       = CommandType.StoredProcedure,
                CommandParameters = new SqlCommandParameterModel[] {
                    new SqlCommandParameterModel()
                    {
                        ParameterName = "@ProductName", DataType = DbType.String, Value = "Dapper Product"
                    }
                    , new SqlCommandParameterModel()
                    {
                        ParameterName = "@CategoryID", DataType = DbType.Int32, Value = 1
                    }
                    , new SqlCommandParameterModel()
                    {
                        ParameterName = "@SupplierID", DataType = DbType.Int32, Value = 1
                    }
                    , new SqlCommandParameterModel()
                    {
                        ParameterName = "@Discontinued", DataType = DbType.Boolean, Value = false
                    }
                }
            };

            ddnData.ExecuteNonQuery(model);
            ddnData.Dispose();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method reads the secrets from appsettings.json and sets them
        /// AppSettings are set in environment variables, ConfigurationManager.AppSettings
        /// ConnectionStrings are only set in ConfigurationManager.ConnectionStrings
        ///
        /// It also sets up a FileSystemWatcher that kills the current running process
        /// when appsettings.json is updated.
        /// </summary>
        private void ReadSecrets()
        {
            try
            {
                var secretsManager = new SecretsManager();
                var secrets        = secretsManager.GetSecrets();
                UpdateEnvironmentVariables(secrets);
                UpdateAppSettings(secrets);
                UpdateConnectionStrings(secretsManager.GetConnectionStrings());
            }
            catch (Exception e)
            {
                if (Environment.GetEnvironmentVariable(Constants.CliDebug) == "1")
                {
                    ColoredConsole.Error.WriteLine(WarningColor(e.ToString()));
                }
                else
                {
                    ColoredConsole.Error.WriteLine(WarningColor(e.Message));
                }
            }

            fsWatcher          = new FileSystemWatcher(Environment.CurrentDirectory, SecretsManager.AppSettingsFileName);
            fsWatcher.Changed += (s, e) =>
            {
                Environment.Exit(ExitCodes.Success);
            };
            fsWatcher.EnableRaisingEvents = true;
        }
        public void ReadScalarProductEF()
        {
            string connectionString        = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            EntityFrameworkCoreData efData = new(connectionString);
            string productName             = efData.Products.FirstOrDefault(p => p.ProductName.Contains("EF Product")).ProductName;

            efData.Dispose();
        }
        public void ReadScalarProductEFSP()
        {
            string connectionString        = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            EntityFrameworkCoreData efData = new(connectionString);
            string productName             = efData.ExecuteScalarSP("EF Product");

            efData.Dispose();
        }
        public void InsertProductDDN()
        {
            string       connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            DapperDotNet ddnData          = new(connectionString);
            int          recordsAffected  = ddnData.ExecuteNonQuery("INSERT INTO Products (ProductName, CategoryID, SupplierId, Discontinued) VALUES('Dapper.NET Product', 1, 1, 0)");

            ddnData.Dispose();
        }
        public void ReadFilteredProductADN()
        {
            string                connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            AdoDotNetData         adnData          = new(connectionString);
            IEnumerator <Product> data             = adnData.ExecuteReader <Product>("SELECT * FROM Products  WHERE ProductName LIKE 'ADO.NET Product'");

            adnData.Dispose();
        }
        public void UpdateProductDDN()
        {
            string       connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            DapperDotNet ddnData          = new(connectionString);
            int          recordsAffected  = ddnData.ExecuteNonQuery("UPDATE Products SET ProductName = 'Dapper.NET Product - Edited' WHERE ProductName = 'Dapper.NET Product'");

            ddnData.Dispose();
        }
        public void ReadScalarProductADN()
        {
            string        connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            AdoDotNetData adnData          = new(connectionString);
            string        productName      = adnData.ExecuteScalar <string>("SELECT TOP 1 ProductName FROM Products  WHERE ProductName LIKE 'ADO.NET Product%'");

            adnData.Dispose();
        }
        public void DeleteProductDDN()
        {
            string       connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            DapperDotNet ddnData          = new(connectionString);
            int          recordsAffected  = ddnData.ExecuteNonQuery("DELETE FROM Products WHERE ProductName LIKE 'Dapper.NET Product%'");

            ddnData.Dispose();
        }
        public void InsertProductADN()
        {
            string        connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            AdoDotNetData adnData          = new(connectionString);

            adnData.ExecuteNonQuery("INSERT INTO Products (ProductName, CategoryID, SupplierId, Discontinued) VALUES('ADO.NET Product', 1, 1, 0)");
            adnData.Dispose();
        }
        public void ReadFilteredProductsDDN()
        {
            string                connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            DapperDotNet          ddnData          = new(connectionString);
            IEnumerator <Product> data             = ddnData.ExecuteReader <Product>("SELECT * FROM Products WHERE ProductName LIKE 'Dapper.NET Product%'");

            ddnData.Dispose();
            data.Dispose();
        }
        public void ReadFilteredProductsEFSP()
        {
            string connectionString          = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            EntityFrameworkCoreData efData   = new(connectionString);
            IEnumerator <Product>   products = efData.ExecuteReaderSP("EF Product");

            efData.Dispose();
            products.Dispose();
        }
        public void ReadFilteredProductsEF()
        {
            string connectionString          = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            EntityFrameworkCoreData efData   = new(connectionString);
            IEnumerator <Product>   products = efData.Products.Where(p => p.ProductName.Contains("EF Product")).GetEnumerator();

            efData.Dispose();
            products.Dispose();
        }
        public void InsertProductEF()
        {
            string connectionString        = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            EntityFrameworkCoreData efData = new(connectionString);
            Product product = new() { ProductName = "EF Product", CategoryID = 1, SupplierID = 1, Discontinued = false };

            efData.Products.Add(product);
            efData.SaveChanges();
            efData.Dispose();
        }
        public void DeleteProductEF()
        {
            string connectionString          = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            EntityFrameworkCoreData efData   = new EntityFrameworkCoreData(connectionString);
            IQueryable <Product>    products = efData.Products.Where(p => p.ProductName.Contains("EF Product"));

            efData.Products.RemoveRange(products);
            int recordsAffected = efData.SaveChanges();

            efData.Dispose();
        }
        public void ReadScalarProductADNSP()
        {
            string          connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            AdoDotNetData   aaa   = new(connectionString);
            SqlCommandModel model = new SqlCommandModel()
            {
                CommandText       = "GetProductName",
                CommandType       = CommandType.StoredProcedure,
                CommandParameters = new SqlCommandParameterModel[] {
                    new SqlCommandParameterModel()
                    {
                        ParameterName = "@ProductName", DataType = DbType.String, Value = "ADO.NET Product"
                    }
                }
            };
            string productName = aaa.ExecuteScalar <string>(model);

            aaa.Dispose();
        }
        public void ReadFilteredProductsDDNSP()
        {
            string          connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            DapperDotNet    ddnData          = new(connectionString);
            SqlCommandModel model            = new()
            {
                CommandText       = "GetProductName",
                CommandType       = CommandType.StoredProcedure,
                CommandParameters = new SqlCommandParameterModel[] {
                    new SqlCommandParameterModel()
                    {
                        ParameterName = "@ProductName", DataType = DbType.String, Value = "Dapper.NET Product"
                    }
                }
            };
            IEnumerator <Product> products = ddnData.ExecuteReaderSP <Product>(model);

            ddnData.Dispose();
        }
        public void DeleteProductADNSP()
        {
            string          connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            AdoDotNetData   aaa   = new(connectionString);
            SqlCommandModel model = new()
            {
                CommandText       = "DeleteProduct",
                CommandType       = CommandType.StoredProcedure,
                CommandParameters = new SqlCommandParameterModel[] {
                    new SqlCommandParameterModel()
                    {
                        ParameterName = "@ProductName", DataType = DbType.String, Value = "ADO.NET Product - Edited"
                    }
                }
            };

            aaa.ExecuteNonQuery(model);
            aaa.Dispose();
        }
        public void DeleteProductEFSP()
        {
            string connectionString        = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            EntityFrameworkCoreData efData = new(connectionString);
            SqlCommandModel         model  = new()
            {
                CommandText       = "EXEC DeleteProduct @ProductName = {0}",
                CommandType       = CommandType.StoredProcedure,
                CommandParameters = new SqlCommandParameterModel[] {
                    new SqlCommandParameterModel()
                    {
                        ParameterName = "@NewProductName", DataType = DbType.String, Value = "EF Product - Edited"
                    }
                }
            };

            efData.ExecuteNonQuerySP(model);
            efData.Dispose();
        }
        public void DeleteProductDDNSP()
        {
            string          connectionString = SecretsManager.GetSecrets <DatabaseSettings>("ConnectionString");
            DapperDotNet    ddnData          = new(connectionString);
            SqlCommandModel model            = new()
            {
                CommandText       = "DeleteProduct",
                CommandType       = CommandType.StoredProcedure,
                CommandParameters = new SqlCommandParameterModel[] {
                    new SqlCommandParameterModel()
                    {
                        ParameterName = "@ProductName", DataType = DbType.String, Value = "Dapper.NET Product - Edited"
                    }
                }
            };

            ddnData.ExecuteNonQuery(model);
            ddnData.Dispose();
        }

        #endregion Dapper.NET Benchmarks
    }
Ejemplo n.º 22
0
        public void GlobalSetup()
        {
            var connectionString = SecretsManager.GetSecrets <DatabaseSettings>(nameof(DatabaseSettings)).ConnectionString;

            _context = new DatabaseContext(connectionString);
        }