Exemple #1
0
        private static void BulkInsert()
        {
            using (EntitiesModel context = new EntitiesModel())
            {
                List<Product> productsNew = new List<Product>();
                for (int i = 0; i < 1000; i++)
                {
                    productsNew.Add(new Product() { Discontinued = false, ProductName = "Product" + i });
                }

                context.Add(productsNew);
                context.SaveChanges();
            }
        }
Exemple #2
0
        private static MemoryStream SerializeToBinaryStream(string customerId)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            MemoryStream stream = new MemoryStream();

            using (EntitiesModel dbContext = new EntitiesModel())
            {
                Customer customer = dbContext.Customers.Where(c => c.CustomerID == customerId).First();
                formatter.Serialize(stream, customer);
            }

            return stream;
        }
Exemple #3
0
        private static TimeSpan SlowDelete()
        {
            using (EntitiesModel context = new EntitiesModel())
            {
                Stopwatch watch = new Stopwatch();

                var customersToRemove = from product in context.Products
                                        where (product.ProductID > 80)
                                        select product;

                watch.Start();
                context.Delete(customersToRemove);
                //context.Delete(context.Products.Where(p => p.ProductID % 7 == 2 && p.ProductID > 80));
                context.SaveChanges();
                watch.Stop();

                return watch.Elapsed;
            }
        }
Exemple #4
0
        static void Main()
        {
            // Task 1
            Customer customer = new Customer();
            customer.PropertyChanged += Write;
            customer.Address = "ba";

            // Task 2
            var serializedStream = SerializeToBinaryStream("ALFKI");

            // Task 3
            BulkInsert();
            TimeSpan timeToDeleteSlow = SlowDelete();

            using (EntitiesModel context = new EntitiesModel())
            {
                var query = from product in context.Products
                            where (product.SupplierID == null)
                            select customer;

                query.DeleteAll();
            }
        }