コード例 #1
0
ファイル: Program.cs プロジェクト: Boyan1912/DataBases
        static void Main()
        {
            var db = new NORTHWNDEntities();
            var pesho = new Customer()
            {
                CustomerID = "Pesho",
                CompanyName = "Pesho's Company"
            };

               // DAO.InsertCustomer(pesho, db);
               // DAO.DeleteCustomer(pesho.CustomerID, db);
               // DAO.ModifyCustomerInfo("ANATR", db, "NEW COMPANY", "Pesho");

            foreach (var cust in DAO.GetCustomersByOrderDateAndShippingCountry(1997, "Canada", db))
            {
                Console.WriteLine(cust.ContactName);
                Console.WriteLine(cust.Country);
            }

            Console.WriteLine(new string('=', 30));
            foreach (var customerName in DAO.GetCustomersByOrderDateAndShippingCountryNativeSQL(db))
            {
                Console.WriteLine(customerName);
            }

            Console.ReadKey();
        }
コード例 #2
0
ファイル: DAO.cs プロジェクト: Boyan1912/DataBases
        public static HashSet<Customer> GetCustomersByOrderDateAndShippingCountry(int year, string shippingDestination, NORTHWNDEntities dataBase)
        {
            var result = dataBase.Orders.Where(o => o.OrderDate.Value.Year == year && o.ShipCountry == shippingDestination)
                            .Select(o => o.Customer)
                            .ToList();

            var hashSet = new HashSet<Customer>(result);
            return hashSet;
        }
コード例 #3
0
ファイル: DAO.cs プロジェクト: Boyan1912/DataBases
        public static IList<string> GetCustomersByOrderDateAndShippingCountryNativeSQL(NORTHWNDEntities dataBase)
        {
            var result = new List<Customer>();

            string sqlQuery =
                "SELECT DISTINCT c.ContactName " +
                "FROM Customers c " +
                "JOIN Orders o " +
                "ON c.CustomerID = o.CustomerID " +
                "WHERE YEAR(o.OrderDate) = 1997 " +
                "AND o.ShipCountry = 'Canada';";

            var customers = dataBase.Database.SqlQuery<string>(sqlQuery).ToList();

            return customers;
        }
コード例 #4
0
ファイル: DAO.cs プロジェクト: Boyan1912/DataBases
        public static void ModifyCustomerInfo(string customerId, NORTHWNDEntities dataBase, string companyName = null, string contactName = null, string contactTitle = null, string address = null, string city = null, string region = null, string postalCode = null, string country = null, string phone = null, string fax = null)
        {
            var customer = dataBase.Customers.FirstOrDefault(x => x.CustomerID.ToLower() == customerId.ToLower());

            customer.CompanyName = companyName;
            customer.ContactName = contactName;
            customer.ContactTitle = contactTitle;
            customer.Address = address;
            customer.City = city;
            customer.Region = region;
            customer.PostalCode = postalCode;
            customer.Country = country;
            customer.Phone = phone;
            customer.Fax = fax;

            dataBase.SaveChanges();
        }
コード例 #5
0
ファイル: DAO.cs プロジェクト: Boyan1912/DataBases
 public static void InsertCustomer(Customer customer, NORTHWNDEntities dataBase)
 {
     dataBase.Customers.Add(customer);
     dataBase.SaveChanges();
 }
コード例 #6
0
ファイル: DAO.cs プロジェクト: Boyan1912/DataBases
 public static void DeleteCustomer(string customerId, NORTHWNDEntities dataBase)
 {
     var customer = dataBase.Customers.FirstOrDefault(x => x.CustomerID.ToLower() == customerId.ToLower());
     dataBase.Customers.Remove(customer);
     dataBase.SaveChanges();
 }