示例#1
0
 static void Delete(string customerID)
 {
     var db = new northwindEntities();
     using (db)
     {
         var customerToDelete = db.Customers.Find(customerID);
         db.Customers.Remove(customerToDelete);
         db.SaveChanges();
     }
 }
示例#2
0
        static void Delete(string customerID)
        {
            var db = new northwindEntities();

            using (db)
            {
                var customerToDelete = db.Customers.Find(customerID);
                db.Customers.Remove(customerToDelete);
                db.SaveChanges();
            }
        }
示例#3
0
 static void Edit(string customerID, string companyName, string city, string country)
 {
     var db = new northwindEntities();
     using (db)
     {
         var customerToEdt = db.Customers.Find(customerID);
         customerToEdt.CompanyName = companyName;
         customerToEdt.City = city;
         customerToEdt.Country = country;
         db.SaveChanges();
     }
 }
示例#4
0
        static void Edit(string customerID, string companyName, string city, string country)
        {
            var db = new northwindEntities();

            using (db)
            {
                var customerToEdt = db.Customers.Find(customerID);
                customerToEdt.CompanyName = companyName;
                customerToEdt.City        = city;
                customerToEdt.Country     = country;
                db.SaveChanges();
            }
        }
示例#5
0
        static void FindCustomersOrdersByYearAndCountry(int year, string country)
        {
            var db = new northwindEntities();
            using (db)
            {
                var findedOrders = db.Orders
                    .Where(x => x.OrderDate.Value.Year == year)
                    .Where(x => x.ShipCountry == country);

                foreach (var order in findedOrders)
                {
                    Console.WriteLine("Customer Name " + order.Customer.ContactName + "Customer ID " + order.Customer.CustomerID);
                }
            }
        }
示例#6
0
        static void FindCustomersOrdersByYearAndCountry(int year, string country)
        {
            var db = new northwindEntities();

            using (db)
            {
                var findedOrders = db.Orders
                                   .Where(x => x.OrderDate.Value.Year == year)
                                   .Where(x => x.ShipCountry == country);

                foreach (var order in findedOrders)
                {
                    Console.WriteLine("Customer Name " + order.Customer.ContactName + "Customer ID " + order.Customer.CustomerID);
                }
            }
        }
示例#7
0
        static void Add(string customerID, string companyName, string city, string country)
        {
            var db = new northwindEntities();
            using(db)
            {
                var customer = new Customer() {
                    CustomerID = customerID,
                    CompanyName = companyName,
                    City = city,
                    Country = country
                };

                db.Customers.Add(customer);
                db.SaveChanges();
            }
        }
示例#8
0
        static void Add(string customerID, string companyName, string city, string country)
        {
            var db = new northwindEntities();

            using (db)
            {
                var customer = new Customer()
                {
                    CustomerID  = customerID,
                    CompanyName = companyName,
                    City        = city,
                    Country     = country
                };

                db.Customers.Add(customer);
                db.SaveChanges();
            }
        }
示例#9
0
        static void NativeSql(int year, string country)
        {
            var db = new northwindEntities();

            using (db)
            {
                string sqlQuery = @"SELECT c.ContactName from Customers" +
                                  " c INNER JOIN Orders o ON o.CustomerID = c.CustomerID " +
                                  "WHERE (YEAR(o.OrderDate) = {0} AND o.ShipCountry = {1});";

                object[] parameters     = { year, country };
                var      sqlQueryResult = db.Database.SqlQuery <string>(sqlQuery, parameters);

                foreach (var order in sqlQueryResult)
                {
                    Console.WriteLine(order);
                }
            }
        }
示例#10
0
        static void FindSalesByDateRange(string region, DateTime startDate, DateTime endDate)
        {
            var db = new northwindEntities();

            using (db)
            {
                var sales = db.Orders
                            .Where(x => x.ShipRegion == region &&
                                   x.OrderDate > startDate &&
                                   x.OrderDate < endDate)
                            .Select(x => new
                {
                    ShipDate = x.ShippedDate,
                    Region   = x.ShipRegion
                });

                db.SaveChanges();
                foreach (var sale in sales)
                {
                    Console.WriteLine("Ship date " + sale.ShipDate + " Ship Region " + sale.Region);
                }
            }
        }
示例#11
0
        static void FindSalesByDateRange(string region, DateTime startDate, DateTime endDate)
        {
            var db = new northwindEntities();
            using (db)
            {
                var sales = db.Orders
                    .Where(x => x.ShipRegion == region
                    && x.OrderDate > startDate
                    && x.OrderDate < endDate)
                    .Select(x => new
                    {
                        ShipDate = x.ShippedDate,
                        Region = x.ShipRegion
                    });

                db.SaveChanges();
                foreach (var sale in sales)
                {
                    Console.WriteLine("Ship date " + sale.ShipDate + " Ship Region " +  sale.Region);
                }

            }
        }
示例#12
0
        static void NativeSql(int year, string country)
        {
            var db = new northwindEntities();
            using (db)
            {
                string sqlQuery = @"SELECT c.ContactName from Customers" +
                            " c INNER JOIN Orders o ON o.CustomerID = c.CustomerID " +
                            "WHERE (YEAR(o.OrderDate) = {0} AND o.ShipCountry = {1});";

                object[] parameters = { year, country };
                var sqlQueryResult = db.Database.SqlQuery<string>(sqlQuery, parameters);

                foreach (var order in sqlQueryResult)
                {
                    Console.WriteLine(order);
                }
            }
        }