static void InsertOrder( string shipName, string shipAddress, string shipCity, string shipRegionm, string shipPostalCode, string shipCountry, string customerID = null, int? employeeID = null, DateTime? orderDate = null, DateTime? requiredDate = null, DateTime? shippedDate = null, int? shipVia = null, decimal? freight = null) { using (NORTHWNDEntities context = new NORTHWNDEntities()) { Order newOrder = new Order { ShipAddress = shipAddress, ShipCity = shipCity, ShipCountry = shipCountry, ShipName = shipName, ShippedDate = shippedDate, ShipPostalCode = shipPostalCode, ShipRegion = shipRegionm, ShipVia = shipVia, EmployeeID = employeeID, OrderDate = orderDate, RequiredDate = requiredDate, Freight = freight, CustomerID = customerID }; context.Orders.Add(newOrder); context.SaveChanges(); Console.WriteLine("Row is inserted."); } }
static void Main(string[] args) { using (TransactionScope scope = new TransactionScope()) { using (NORTHWNDEntities context = new NORTHWNDEntities()) { InsertMultiple(); } scope.Complete(); } }
static void Main() { NORTHWNDEntities northwind = new NORTHWNDEntities(); Employee employeeExtended = new Employee(); employeeExtended = northwind.Employees.Find(1); foreach (var item in employeeExtended.EntityTerritories) { Console.WriteLine("Decription of territory: {0}",item.TerritoryDescription); } }
static void Main() { using (NORTHWNDEntities northwindEntities1 = new NORTHWNDEntities()) { using (NORTHWNDEntities northwindEntities2 = new NORTHWNDEntities()) { Customer editedCustomer1 = northwindEntities1.Customers.Find("WELLI"); editedCustomer1.Region = "SP1"; Customer editedCustomer2 = northwindEntities2.Customers.Find("WELLI"); editedCustomer2.Region = "SP2"; northwindEntities1.SaveChanges(); northwindEntities2.SaveChanges(); } } }
static void Main(string[] args) { IObjectContextAdapter objectContext = new NORTHWNDEntities(); string generatedScript = objectContext.ObjectContext.CreateDatabaseScript(); string dbScript = "CREATE DATABASE NorthwindTwin ON PRIMARY " + "(NAME = NorthwindTwin, " + "FILENAME = 'E:\\NorthwindTwin.mdf', " + "SIZE = 5MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " + "LOG ON (NAME = NorthwindTwinLog, " + "FILENAME = 'E:\\NorthwindTwin.ldf', " + "SIZE = 1MB, " + "MAXSIZE = 5MB, " + "FILEGROWTH = 10%)"; string strDbConn = "Server=LOCALHOST;Database=master;Integrated Security=true"; SqlConnection dbConn = new SqlConnection(strDbConn); dbConn.Open(); using (dbConn) { SqlCommand createDB = new SqlCommand(dbScript, dbConn); createDB.ExecuteNonQuery(); } string strDbConnCloning = "Server=LOCALHOST;Database=NorthwindTwin;Integrated Security=true"; SqlConnection dbConnCloning = new SqlConnection(strDbConnCloning); dbConnCloning.Open(); using (dbConnCloning) { SqlCommand cloneDb = new SqlCommand(generatedScript, dbConnCloning); cloneDb.ExecuteNonQuery(); } }
static void Main() { northwindEntities = new NORTHWNDEntities(); string newCustomerName = InsertCustomer("WIKON","Ivkony Union"); Console.WriteLine("Inserted new customer with name {0}.",newCustomerName ); Customer editedCustomer = ModifyCustomer("WIKON", "Ivan Ivanov"); Console.WriteLine("Added contact name {0} to company name {1}",editedCustomer.ContactName,editedCustomer.CompanyName); Console.WriteLine("Print all customers before deleted customer with Company name {0}: ", editedCustomer.CompanyName); PrintCustomers(); DeleteCustomer(editedCustomer.CustomerID); Console.WriteLine("\nPrint all customers after delete customer with Company name {0}: ", editedCustomer.CompanyName); PrintCustomers(); Console.WriteLine(); CustomersWithOrders(); Console.WriteLine("\nAfter running native SQL Query"); IEnumerable<CustomerOrder> result = ReportForCanadaAnd1997(); Console.WriteLine("{0,-40} {1,-30} {2,-30} {3,-20}","Customer Name", "Contact Name", "Order Date", "Ship Country"); foreach (var item in result) { Console.WriteLine("{0,-40} {1,-30} {2,-30} {3,-20}", item.CompanyName, item.ContactName, item.OrderDate, item.ShipCountry); } Console.WriteLine("\nOrders by specific region"); OrdersBySpecigicRegionAnYear("UK", new DateTime(1998, 1, 1), new DateTime(1998, 3, 31)); }