Ejemplo n.º 1
0
 private static void Warmup()
 {
     using (var db = new NorthwindDb())
     {
         db.Customers.Where(c => c.CustomerID == "-1").ToList();
     }
 }
        /// <summary>
        /// In Order to make this Demo work, you have to comment the IsUnicode Configuration 
        /// for the PreferedCommunication Column in the DB Context On Model Creating Method.
        /// This will cause code first to assume a wrong column type which will miss some index
        /// uses
        /// </summary>
        public void Problem()
        {
            Console.WriteLine("Column Type Demo");
            using (var db = new NorthwindDb())
            {
                var faxCustomers = db.Customers.Where(c => c.PreferedCommunication == "Fax").ToList();
                Console.WriteLine("{0} Customers", faxCustomers.Count);

            }
        }
Ejemplo n.º 3
0
        public void Problem()
        {
            Console.WriteLine("Contains Demo");
            using (var db = new NorthwindDb())
            {
                var customers = db.Customers.Where(c => c.PreferedCommunication.Contains("Pho")).ToList();
                Console.WriteLine("{0} Customers", customers.Count);

            }
        }
Ejemplo n.º 4
0
 public void Problem()
 {
     Console.WriteLine("Delete Demo");
     using (var db = new NorthwindDb())
     {
         var maxShipperId = db.Shippers.Max(s => s.ShipperID);
         var shipper = db.Shippers.Find(maxShipperId);
         db.Shippers.Remove(shipper);
         db.SaveChanges();
     }
 }
 public void Solution()
 {
     Console.WriteLine("LateFilterDemo");
     using (var db = new NorthwindDb())
     {
         var customers = GetCustomers2(db).Where(c => c.Country == "Germany");
         foreach (var customer in customers)
         {
             Console.WriteLine("{0} - {1}", customer.CustomerID, customer.CompanyName);
         }
     }
 }
        public void Solution()
        {
            Console.WriteLine("Reloading Entities Demo - Solution");
            using (var db = new NorthwindDb())
            {
                var s1 = db.Shippers.Find(1);
                Console.WriteLine("S1: {0} - {1}", s1.ShipperID, s1.CompanyName);

                var s2 = db.Shippers.Find(1);
                Console.WriteLine("S2: {0} - {1}", s2.ShipperID, s2.CompanyName);
            }
        }
Ejemplo n.º 7
0
 public void Solution()
 {
     Console.WriteLine("Delete Demo - Solution");
     using (var db = new NorthwindDb())
     {
         var maxShipperId = db.Shippers.Max(s => s.ShipperID);
         // db.Shippers.Find(maxShipperId);
         var shipper = new Shippers {ShipperID = maxShipperId};
         db.Shippers.Attach(shipper);
         db.Shippers.Remove(shipper);
         db.SaveChanges();
     }
 }
 public void Solution()
 {
     Console.WriteLine("ChangeTrackingDemo - Solution");
     using (var db = new NorthwindDb())
     {
         var shippers = db.Shippers.AsNoTracking().ToList();
         for (int i = 0; i < 200 && i < shippers.Count; i++)
         {
             var shipper = shippers[i];
             Console.WriteLine("{0} - {1}", shipper.ShipperID, shipper.CompanyName);
         }
     }
 }
        public void Problem()
        {
            Console.WriteLine("Late Filter Demo 2");
            using (var db = new NorthwindDb())
            {
                var shippers = db.Shippers.ToList().Take(10);

                foreach (var shipper in shippers)
                {
                    Console.WriteLine("{0} - {1}", shipper.ShipperID, shipper.CompanyName);
                }
            }
        }
        public void Problem()
        {
            Console.WriteLine("ProjectionDemo");
            using (var db = new NorthwindDb())
            {
                var products = db.Products;

                foreach (var product in products)
                {
                    Console.WriteLine("{0}", product.ProductName);
                }
            }
        }
Ejemplo n.º 11
0
        public void Problem()
        {
            Console.WriteLine("Many Rows Demo");
            using (var db = new NorthwindDb())
            {
                var shippers = db.Shippers.ToList();

                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("{0} - {1}", shippers[i].ShipperID, shippers[i].CompanyName);
                }
            }
        }
        public void Problem()
        {
            Console.WriteLine("Reloading Entities Demo");
            using (var db = new NorthwindDb())
            {

                var s1 = db.Shippers.SingleOrDefault(c => c.ShipperID == 1);
                Console.WriteLine("S1: {0} - {1}", s1.ShipperID, s1.CompanyName);

                var s2 = db.Shippers.SingleOrDefault(c => c.ShipperID == 1);
                Console.WriteLine("S2: {0} - {1}", s2.ShipperID, s2.CompanyName);
            }
        }
        public void Solution()
        {
            Console.WriteLine("ProjectionDemo - Solution");
            using (var db = new NorthwindDb())
            {
                var products = db.Products.Select(p => new {p.ProductName});

                foreach (var product in products)
                {
                    Console.WriteLine("{0}", product.ProductName);
                }

            }
        }
Ejemplo n.º 14
0
        public void Solution()
        {
            Console.WriteLine("Many Rows Demo - Solution");
            using (var db = new NorthwindDb())
            {
                var shippers = db.Shippers.Take(10).ToList();

                foreach (var shipper in shippers)
                {
                    Console.WriteLine("{0} - {1}", shipper.ShipperID, shipper.CompanyName);
                }

            }
        }
 private IQueryable<Customers> GetCustomers2(NorthwindDb db)
 {
     return db.Customers;
 }
 private IEnumerable<Customers> GetCustomers(NorthwindDb db)
 {
     return db.Customers;
 }