Exemplo n.º 1
0
        public static void InsertOrder(int orderId, string customerId, int employeeId, DateTime orderDate,
                                        DateTime requiredDate, DateTime shippedDate, int? shipVia, decimal? freight,
                                        string shipName, string shipAddress, string shipCity, string shipRegion,
                                        string shipPostalCode, string shipCountry)
        {
            NorthwindEntities db = new NorthwindEntities();
            using (db)
            {
                Order newOrder = new Order();
                newOrder.OrderID = orderId;
                newOrder.CustomerID = customerId;
                newOrder.EmployeeID = employeeId;
                newOrder.OrderDate = orderDate;
                newOrder.RequiredDate = requiredDate;
                newOrder.ShippedDate = shippedDate;
                newOrder.ShipVia = shipVia;
                newOrder.Freight = freight;
                newOrder.ShipName = shipName;
                newOrder.ShipAddress = shipAddress;
                newOrder.ShipCity = shipCity;
                newOrder.ShipRegion = shipRegion;
                newOrder.ShipPostalCode = shipPostalCode;
                newOrder.ShipCountry = shipCountry;

                db.Orders.Add(newOrder);
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            using (var transaction = new TransactionScope())
            {
                NorthwindEntities db = new NorthwindEntities();
                using (db)
                {
                    Order newOrder = new Order();
                    newOrder.OrderID = 1;
                    newOrder.CustomerID = "ALFKI";
                    newOrder.EmployeeID = 3;
                    newOrder.OrderDate = DateTime.Now;
                    newOrder.RequiredDate = DateTime.Now;
                    newOrder.ShippedDate = DateTime.Now;
                    newOrder.ShipVia = 3;
                    newOrder.Freight = 5;
                    newOrder.ShipName = "pesho";
                    newOrder.ShipAddress = "some address";
                    newOrder.ShipCity = "sofia";
                    newOrder.ShipRegion = "PA";
                    newOrder.ShipPostalCode = "sdfdf7";
                    newOrder.ShipCountry = "bg";

                    db.Orders.Add(newOrder);
                    db.SaveChanges();

                    transaction.Complete();
                    ((IObjectContextAdapter)db).ObjectContext.AcceptAllChanges();
                }
            }
        }
Exemplo n.º 3
0
 static void Main()
 {
     using ( var db = new NorthwindEntities() )
     {
         var startDate = new DateTime(1998, 1, 1);
         var endDate = new DateTime(2003, 1, 1);
         var result = db.getIncome("Peter Wilson", startDate, endDate);
         Console.WriteLine(result);
     }
 }
Exemplo n.º 4
0
 static void TestNorthwindContext()
 {
     using (var test = new NorthwindEntities())
     {
         Console.WriteLine("Company name: ");
         foreach (var customer in test.Customers)
         {
             Console.WriteLine(customer.CompanyName);
         }
     }
 }
Exemplo n.º 5
0
        static List<Customer> Find(string region, DateTime startDate, DateTime endDate)
        {
            using (var db = new NorthwindEntities())
            {
                var customers = from o in db.Orders
                                join c in db.Customers on o.CustomerID equals c.CustomerID
                                where
                                    (o.OrderDate > startDate &&
                                    o.OrderDate < endDate &&
                                    o.ShipRegion == region)
                                select c;

                return customers.ToList();
            }
        }
Exemplo n.º 6
0
        static void Main()
        {
            //display city
            using (var db = new NorthwindEntities())
            {
                var list = db.Database.SqlQuery<string>(@"select c.City from Orders o " +
                                                        "join Customers c " +
                                                            "on( (o.OrderDate between " +
                                                                 "CONVERT( DATETIME, '1997/01/01', 111) and " +
                                                                 "CONVERT( DATETIME, '1997/12/30', 111) ) and c.Country = 'Canada')").ToList();

                foreach (var item in list)
                {
                    Console.WriteLine(item);
                }
            }
        }
Exemplo n.º 7
0
        static void Main()
        {
            using (var db = new NorthwindEntities())
            {
                var customers = from o in db.Orders
                                join c in db.Customers on o.CustomerID equals c.CustomerID
                                where
                                    (o.OrderDate > (new DateTime(1997, 1, 1)) &&
                                    o.OrderDate < (new DateTime(1997, 12, 30)) &&
                                    c.Country == "Canada")
                                select c;

                foreach (var customer in customers)
                {
                    Console.WriteLine("{0} {1} {2}", customer.ContactTitle, customer.Country, customer.City);
                }
            }
        }
Exemplo n.º 8
0
        static void TestWithTwoContexts()
        {
            using (var first = new NorthwindEntities())
            {
                using (var second = new NorthwindTwinEntities())
                {
                    Console.WriteLine("From first context: ");
                    foreach (var customer in first.Customers)
                    {
                        Console.WriteLine(customer.CompanyName);
                    }

                    Console.WriteLine("From second context: ");
                    foreach (var customer in second.Customers)
                    {
                        Console.WriteLine(customer.CompanyName);
                    }
                }
            }
        }