static void Main(string[] args)
        {
            northwindEntities db1 = new northwindEntities();
            northwindEntities db2 = new northwindEntities();

            //Categories can be added simultaneously
            for (int i = 0; i < 10; i++)
            {
                db1.Categories.Add(new Category()
                {
                    CategoryName = "NewCategory" + i
                });
                db2.Categories.Add(new Category()
                {
                    CategoryName = "NewCategory" + i
                });
                db1.SaveChanges();
                db2.SaveChanges();
            }

            //Editin same entry
            var firstEntry = db1.Categories.Where((x) => x.CategoryName == "NewCategory0").First();
            firstEntry.CategoryName = "Lol";

            var sameEntry = db2.Categories.Where(x => x.CategoryName == "NewCategory0").First();

            db2.Categories.Remove(sameEntry);

            //Removing an entry before editing it throws an exception
            //db2.SaveChanges();
            db1.SaveChanges();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            northwindEntities db = new northwindEntities();

            var found = GetCustomers(db);

            foreach (var row in found)
            {
                Console.WriteLine(row);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            northwindEntities db = new northwindEntities();

            var found = GetSales(db, "SP", DateTime.Parse("1995-05-10"), DateTime.Parse("1996-09-10"));

            foreach (var row in found)
            {
                Console.WriteLine(row);
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            northwindEntities nwDB = new northwindEntities();

            var clients = from client in nwDB.Customers
                          select client.ContactName;

            foreach (var client in clients)
            {
                Console.WriteLine(client);
            }
        }
        static void Main(string[] args)
        {
            northwindEntities db = new northwindEntities();

            string companyName = "Exotic Liquids";
            var startDate = DateTime.Parse("1980.01.21");
            var endDate = DateTime.Parse("1999.01.22");

            var income = db.uspSupplierIncome(companyName, startDate, endDate).First();

            Console.WriteLine(income);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            string query = "SELECT cust.ContactName FROM Customers cust " +
            "INNER JOIN Orders ord " +
            "ON ord.CustomerID = cust.CustomerID " +
            "WHERE YEAR(ord.OrderDate) = {0} AND ord.ShipCountry = {1} ";

            object[] parameters = { 1997, "Canada" };

            using (var context = new northwindEntities())
            {
                var ContactNames = context.Database.SqlQuery<string>(query,parameters).ToList();

                foreach (var name in ContactNames)
                {
                    Console.WriteLine("{0}", name);
                }
            }
        }
Esempio n. 7
0
        private static IEnumerable<string> GetCustomers(northwindEntities db)
        {
            var customers = (from customer in db.Customers
                             join ord in db.Orders
                             on customer.CustomerID equals ord.CustomerID
                             where ord.OrderDate.Value.Year == 1997 &&
                             ord.ShipCountry == "Canada"
                             select new
                             {
                                 CustomerID = customer.CustomerID,
                                 ContactName = customer.ContactName,
                                 OrderID = ord.OrderID,
                                 OrderDate = ord.OrderDate
                             }
                            ).Distinct();

            foreach (var item in customers)
            {
                yield return string.Format("{0} {1} - order ID:{2}, order Date: {3}",
                    item.CustomerID, item.ContactName, item.OrderID, item.OrderDate.Value.ToShortDateString());
            }
        }
Esempio n. 8
0
        private static IEnumerable<string> GetSales(northwindEntities db, 
            string Region, DateTime startDate, DateTime endDate)
        {
            var sales = (from invoice in db.Invoices
                             where invoice.Region == Region &&
                             invoice.OrderDate > startDate &&
                             invoice.OrderDate < endDate
                             select new
                             {
                                 OrderID = invoice.OrderID,
                                 OrderDate = invoice.OrderDate,
                                 ProductName = invoice.ProductName,
                                 ExtendedPrice = invoice.ExtendedPrice
                             }
                            );

            foreach (var item in sales)
            {
                yield return string.Format("ID:{0}    OrderDate: {1}\nProduct Name:{2}, Price: {3}\n",
                    item.OrderID, item.OrderDate, item.ProductName, item.ExtendedPrice);
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            IObjectContextAdapter context = new northwindEntities();
            string cloneNorthwind = context.ObjectContext.CreateDatabaseScript();

            var db = new northwindEntities();

            string[] splitter = new string[] { "\r\nGO\r\n" };
            string[] commandTexts = createDB.Split(splitter,
              StringSplitOptions.RemoveEmptyEntries);
            foreach (string commandText in commandTexts)
            {
                db.Database.ExecuteSqlCommand(commandText);
            }

            SqlConnection dbConForCreatingDB = new SqlConnection(
            "Server=.; " +
            "Database=NorthwindTwin; " +
            "Integrated Security=true");

            dbConForCreatingDB.Open();

            using (dbConForCreatingDB)
            {
                SqlCommand cloneDB = new SqlCommand(cloneNorthwind, dbConForCreatingDB);
                cloneDB.ExecuteNonQuery();
            }
        }