Exemplo n.º 1
0
 static void ModifyNewInsertedCustomer()
 {
     var dataBase = new NorthwindEntities();
     var customer = dataBase.Customers.First();
     customer.ContactTitle = "CEO";
     affectedRows = dataBase.SaveChanges();
     Console.WriteLine("({0} row(s) affected)", affectedRows);
 }
Exemplo n.º 2
0
 static void DeleteNewInsertedCustomer()
 {
     var dataBase = new NorthwindEntities();
     var customer = dataBase.Customers.First();
     dataBase.Customers.Remove(customer);
     affectedRows = dataBase.SaveChanges();
     Console.WriteLine("({0} row(s) affected)", affectedRows);
 }
Exemplo n.º 3
0
 static void Main(string[] args)
 {
     using (var dataBase = new NorthwindEntities())
     {
         var customers = dataBase.Customers.Where(c => c.Orders.Any(x => x.OrderDate != null && (x.OrderDate.Value.Year == 1997 && x.ShipCountry == "Canada"))).ToList();
         foreach (var item in customers)
         {
             Console.WriteLine(customers);
         }
     }
 }
Exemplo n.º 4
0
 static void Main(string[] args)
 {
     using (var dataBase = new NorthwindEntities())
     {
         foreach (var employee in dataBase.Employees.Include("Territories"))
         {
             var correspondingTerritories = employee.Territories.Select(c => c.TerritoryID);
             var correspondingTerritoriesAsString = string.Join(", ", correspondingTerritories);
             Console.WriteLine("{0} -> Territory IDs: {1}", employee.FirstName, correspondingTerritoriesAsString);
         }
     }
 }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            using (var dataBase = new NorthwindEntities())
            {
                Console.WriteLine("Executing queries...");
                Thread.Sleep(1000);
                InsertNewCustomersToDb();
                Thread.Sleep(1000);
                ModifyNewInsertedCustomer();
                Thread.Sleep(1000);

            }
            Console.WriteLine("-- Closing connection to the database...");
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            const string region = "SP";
            var startDate = new DateTime(1995, 4, 9);
            var endDate = new DateTime(2001, 2, 1);

            using (var dataBase = new NorthwindEntities())
            {
                var sales = dataBase.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);
                }
            }
        }
Exemplo n.º 7
0
 static void Main(string[] args)
 {
     NorthwindEntities northwindEntities = new NorthwindEntities();
     string nativeSqlQuery =
         "SELECT c.ContactName AS [Customer], o.OrderDate [Order Year],o.ShipCountry " +
         "FROM dbo.Orders o,dbo.Customers c " +
         "WHERE c.CustomerID = o.CustomerID AND YEAR(o.OrderDate) = 1997 AND o.ShipCountry = 'Canada'";
     using (var dataBase = new NorthwindEntities())
     {
         var customers = dataBase.Database.SqlQuery<View>(nativeSqlQuery);
         foreach (var customer in customers)
         {
             Console.WriteLine(customer);
         }
     }
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            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);
            }
        }
Exemplo n.º 9
0
        static void InsertNewCustomersToDb()
        {
            var dataBase = new NorthwindEntities();
            var newCustomer = new Customer
            {
                CustomerID = "AAAAA",
                CompanyName = "Lethal Corporation",
                ContactName = "Alfonso Salvarez",
                ContactTitle = "CEO",
                Address = "33 Pedro Almodovar Sq.",
                City = "Ciudad Real",
                Region = "BC",
                PostalCode = "11223",
                Country = "Spain",
                Phone = "030-0023002",
                Fax = "030-0023003"

            };
            dataBase.Customers.Add(newCustomer);
            affectedRows = dataBase.SaveChanges();
            Console.WriteLine("({0} row(s) affected)", affectedRows);
        }