Esempio n. 1
0
        /// <summary>
        /// In order for this to create a twin base of NORTHWIND you have to change 
        /// the 'initial catalog' to the name of the twin db (NORTHWINDtwin in this case)
        /// This will create a twin base ONLY if no such base with the same name exists in MSSQL database catalog
        /// </summary>
        public static void Main()
        {
            var dbContext = new NORTHWNDEntities();

            CreateTwinDatabase(dbContext);

            // DeleteDatabase(dbContext);
        }
Esempio n. 2
0
 public static void Main(string[] args)
 {
     using (var db = new NORTHWNDEntities())
     {
         foreach (var employee in db.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);
         }
     }
 }
Esempio n. 3
0
 private static void SelectEmployeeNamesByCountryAndCity( string country, int year)
 {
     NORTHWNDEntities northwindEntities = new NORTHWNDEntities();
     string nativeSqlQuery =
         "SELECT CONCAT(c.ContactName , ' | ' , o.OrderDate , ' | ' , o.ShipCountry) AS [Customer]" +
         "FROM Customers c " +
         "JOIN Orders o " +
         "ON c.CustomerID = o.CustomerID " +
         "WHERE YEAR(o.OrderDate) = {1} AND o.ShipCountry = {0} " +
         "ORDER BY c.ContactName DESC";
     object[] parameters = { country, year };
     var customers = northwindEntities.Database.SqlQuery<string>(
         nativeSqlQuery, parameters);
     foreach (var emp in customers)
     {
         Console.WriteLine(emp);
     }
 }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            var startDate = new DateTime(1995, 01, 01);
            var endDate = new DateTime(1997, 01, 01);

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

                foreach (var sale in sales)
                {
                    Console.WriteLine("Order ID: " + sale.OrderID);
                    Console.WriteLine(sale.OrderDate);
                }
            }
        }
Esempio n. 5
0
        private static void Main()
        {
            Console.WriteLine("-- Establishing first connection to database Northwind...");

            using (var firstDb = new NORTHWNDEntities())
            {
                var firstCategory = firstDb.Categories.Find(4);
                Console.WriteLine("Initial category description: {0}", firstCategory.Description);

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

                Console.WriteLine("-- Establishing second connection to database Northwind...");

                using (var secondDb = new NORTHWNDEntities())
                {
                    var secondCategory = secondDb.Categories.Find(4);
                    Console.WriteLine("Initial category description: {0}", secondCategory.Description);

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

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

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

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

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

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

            using (var db = new NORTHWNDEntities())
            {
                Console.WriteLine("Actual result: {0}", db.Categories.Find(4).Description);
            }
        }