Exemplo n.º 1
0
        private static void InsertarOrdenDetalleEf()
        {
            using (var contexto = new NorthwndModel())
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var orden = new Order
                {
                    CustomerID    = "VINET",
                    OrderDate     = DateTime.Now,
                    Order_Details =
                    {
                        new Order_Detail
                        {
                            ProductID = 41,
                            UnitPrice = 20,
                            Quantity  = 100,
                            Discount  = 0
                        }
                    }
                };

                contexto.Orders.Add(orden);
                contexto.SaveChanges();

                stopwatch.Stop();
                System.Console.WriteLine("EntityFramework: registros relacionados insertados en {0} milisegundos.",
                                         stopwatch.ElapsedMilliseconds);
            }
        }
Exemplo n.º 2
0
        private static void ConsultarOrdenesDetallesEf()
        {
            using (var contexto = new NorthwndModel())
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var ordenesDetalle = contexto.Orders.Include("Order_Details").ToList();

                stopwatch.Stop();
                System.Console.WriteLine("EntityFramework: {0} registros obtenidos en {1} milisegundos.",
                                         ordenesDetalle.Count, stopwatch.ElapsedMilliseconds);
            }
        }
Exemplo n.º 3
0
        private static void InsertarOrdenEf()
        {
            using (var contexto = new NorthwndModel())
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var orden = new Order
                {
                    CustomerID = "VINET",
                    OrderDate  = DateTime.Now
                };

                contexto.Orders.Add(orden);
                contexto.SaveChanges();

                stopwatch.Stop();
                System.Console.WriteLine("EntityFramework: un registro insertado en {0} milisegundos.",
                                         stopwatch.ElapsedMilliseconds);
            }
        }