public static void InsertCustomer(NorthwindEntities northDb,
            string companyName = null,
            string contractName = null,
            string contractTitle = null,
            string address = null,
            string city = null,
            string region = null,
            string postalCode = null,
            string country = null,
            string phone = null,
            string fax = null)
        {

            using (northDb)
            {
                Customer newCustomer = new Customer();
                newCustomer.CustomerID = "temporaryUnique";
                newCustomer.CompanyName = companyName;
                newCustomer.ContactName = contractName;
                newCustomer.ContactTitle = contractTitle;
                newCustomer.Address = address;
                newCustomer.City = city;
                newCustomer.Region = region;
                newCustomer.PostalCode = postalCode;
                newCustomer.Country = country;
                newCustomer.Phone = phone;
                newCustomer.Fax = fax;

                northDb.Customers.Add(newCustomer);
                northDb.SaveChanges();
            }
        }
Beispiel #2
0
        private static void NativeQueryImplementation(NorthwindEntities northDb)
        {
            string query = "SELECT * FROM Customers WHERE CustomerID IN (SELECT CustomerID FROM Orders WHERE year(OrderDate) = 1997);";

            using (northDb)
            {
                var specificProducts = northDb.Customers.SqlQuery(query).ToList();
            }
        }
        public static void UpdateCustomer(NorthwindEntities northDb, string id, string companyName)
        {
            using (northDb)
            {
                Customer customerToUpdate = (Customer)northDb.Customers.Select(x => x.CustomerID == id);

                customerToUpdate.CompanyName = companyName;
                northDb.SaveChanges();
            }
        }
        public static void DeleteCustomer(NorthwindEntities northDb, string id)
        {
            using (northDb)
            {
                Customer customerToDelete = (Customer)northDb.Customers.Select(x => x.CustomerID == id);

                northDb.Customers.Remove(customerToDelete);
                northDb.SaveChanges();
            }
        }
        public void InsertCustomerShouldSuccessfullyInsertNewCustomer()
        {
            NorthwindEntities northDb = new NorthwindEntities();

            NorthwindOperations.InsertCustomer(northDb, "Progress", "val", "pesho", "john", "siblng", "feeling", "ultimate", "243nand", "random value", "unnecessary");

            using (northDb)
            {
                Customer insertedUser = northDb.Customers.Where(x => x.CompanyName == "Progress").FirstOrDefault();
                Assert.AreEqual("Progress", insertedUser.CompanyName, "Not equal.");
            }
        }
Beispiel #6
0
 private static void FindSpecificCustomers(NorthwindEntities northDb)
 {
     using (northDb)
     {
         var customers = northDb.Orders
             .Where(x => x.OrderDate.Value.Year == 1997 && x.ShipCountry == "Canada")
             .Select(i => new
             {
                 CustomerName = i.Customer.ContactName,
                 OrderDare = i.OrderDate
             })
             .ToList();
     }
 }
Beispiel #7
0
        private static void Main()
        {
            Console.WriteLine("-- Establishing first connection to database Northwind...");
            Thread.Sleep(1000);
            using (var firstDb = new NorthwindEntities())
            {
                var firstCategory = firstDb.Categories.Find(4);
                Console.WriteLine("Initial category description: {0}", firstCategory.Description);
                Thread.Sleep(1000);

                firstCategory.Description = "Cheese and many more";
                Console.WriteLine("Category description after changing: {0}", firstCategory.Description);
                Thread.Sleep(1000);

                Console.WriteLine("-- Establishing second connection to database Northwind...");
                Thread.Sleep(1000);
                using (var secondDb = new NorthwindEntities())
                {
                    var secondCategory = secondDb.Categories.Find(4);
                    Console.WriteLine("Initial category description: {0}", secondCategory.Description);
                    Thread.Sleep(1000);

                    secondCategory.Description = "Cheese and many, many more";
                    Console.WriteLine("Category description after changing: {0}", secondCategory.Description);
                    Thread.Sleep(1000);

                    firstDb.SaveChanges();
                    secondDb.SaveChanges();

                    Console.WriteLine("Category description after saving: {0}", secondCategory.Description);
                    Thread.Sleep(1000);
                }

                Console.WriteLine("-- Closing second connection to the database...");
                Thread.Sleep(1000);

                Console.WriteLine("Category description after saving: {0}", firstCategory.Description);
                Thread.Sleep(1000);
            }

            Console.WriteLine("-- Closing first connection to the database...");

            using (var db = new NorthwindEntities())
            {
                Console.WriteLine("Actual result: {0}", db.Categories.Find(4).Description);
            }
        }
Beispiel #8
0
        private static void Main()
        {
            using (var db = new NorthwindEntities())
            {
                // You must change your App.config file in order to generate a clone of Northwind

                // Summary:
                //     Creates a new database on the database server for the model defined in the backing
                //     context, but only if a database with the same name does not already exist on
                //     the server.
                //
                // Returns:
                //     True if the database did not exist and was created; false otherwise.
                var flag = db.Database.CreateIfNotExists();
                Console.WriteLine(flag);
            }
        }
Beispiel #9
0
        private static void Main()
        {
            const string region = "SP";
            var startDate = new DateTime(1995, 5, 10);
            var endDate = new DateTime(1996, 12, 4);

            using (var db = new NorthwindEntities())
            {
                var sales = db.Orders
                    .Where(o => o.ShipRegion == region &&
                                o.OrderDate >= startDate &&
                                o.OrderDate <= endDate)
                    .ToList();

                foreach (var sale in sales)
                {
                    Console.WriteLine("{0} | {1}", sale.ShipRegion, sale.OrderDate);
                }
            }
        }
Beispiel #10
0
 public static void Main(string[] args)
 {
     NorthwindEntities northDb = new NorthwindEntities();
 }