/// <summary> /// 创建新的 Order 对象。 /// </summary> /// <param name="orderID">OrderID 属性的初始值。</param> public static Order CreateOrder(global::System.Int32 orderID) { Order order = new Order(); order.OrderID = orderID; return order; }
/// <summary> /// 用于向 Orders EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToOrders(Order order) { base.AddObject("Orders", order); }
/// <summary> /// In this demo we are running a set of queries and updates and 3 times and logging SQL commands to the console. /// Notice how performing an update on Customer table causes the cache entry to be invalidated so we get /// a query in each pass. Because we aren't modifying OrderDetails table, the collection of order details /// for the customer doesn't require a query in second and third pass. /// </summary> private static void CacheInvalidationDemo() { var cache = new InMemoryCache(); // log SQL from all connections to the console EFTracingProviderConfiguration.LogToConsole = true; for (int i = 0; i < 3; ++i) { Console.WriteLine(); Console.WriteLine("*** Pass #{0}...", i); Console.WriteLine(); using (var context = new ExtendedNorthwindEntities()) { // set up caching context.Cache = cache; context.CachingPolicy = CachingPolicy.CacheAll; Console.WriteLine("Loading customer..."); var cust = context.Customers.First(c => c.CustomerID == "ALFKI"); Console.WriteLine("Customer name: {0}", cust.ContactName); cust.ContactName = "Change" + Environment.TickCount; Console.WriteLine("Loading orders..."); cust.Orders.Load(); for (int o = 0; o < 10; ++o) { var order = new Order(); order.OrderDate = DateTime.Now; cust.Orders.Add(order); } Console.WriteLine("Order count: {0}", cust.Orders.Count); context.SaveChanges(); } } Console.WriteLine(); }