コード例 #1
0
        public void TestAssociations_GraphDelete()
        {
            NorthwindEntityContainer entities = new NorthwindEntityContainer();

            #region Create a test graph
            Customer cust = new Customer
            {
                CustomerID = "ALFKI"
            };
            Order order = new Order
            {
                OrderID = 1
            };
            order.Customer = cust;
            order.Order_Details.Add(new Order_Detail
            {
                ProductID = 1
            });
            order.Order_Details.Add(new Order_Detail
            {
                ProductID = 2
            });
            order.Order_Details.Add(new Order_Detail
            {
                ProductID = 3
            });

            entities.LoadEntities(new Entity[] { cust, order });
            entities.LoadEntities(order.Order_Details);
            ((IRevertibleChangeTracking)entities).AcceptChanges();
            #endregion

            // now delete the graph
            // TODO : currently this has to be done in this specific order
            // with association modifications being done while the parent
            // is attached (before it is removed from set)
            foreach (Order_Detail detail in order.Order_Details)
            {
                order.Order_Details.Remove(detail);
                entities.GetEntitySet<Order_Detail>().Remove(detail);
            }
            cust.Orders.Remove(order);
            entities.GetEntitySet<Order>().Remove(order);
            entities.GetEntitySet<Customer>().Remove(cust);

            // verify the changeset
            EntityChangeSet changeSet = entities.GetChanges();
            Assert.AreEqual(5, changeSet.RemovedEntities.Count);

            // build the operation list and verify it
            List<ChangeSetEntry> operations = ChangeSetBuilder.Build(changeSet);

            // verify that the association collections for the Order operation are null
            ChangeSetEntry orderOperation = operations.Single(p => p.Entity == order);
            ChangeSetEntry custOperation = operations.Single(p => p.Entity == cust);
            Assert.IsNull(orderOperation.Associations);
            Assert.IsNull(orderOperation.OriginalAssociations);
            Assert.IsNotNull(orderOperation.OriginalEntity);
            
            // verify that the association collections for the Customer operation are null
            Assert.IsNull(custOperation.OriginalEntity);
            Assert.IsNull(custOperation.Associations);
            Assert.IsNull(custOperation.OriginalAssociations);

            // verify that deleted OrderDetails have null associations as well
            ChangeSetEntry detailOperation = operations.First(p => p.Entity.GetType() == typeof(Order_Detail));
            Assert.IsNotNull(detailOperation.OriginalEntity);
            Assert.IsNull(detailOperation.Associations);
            Assert.IsNull(detailOperation.OriginalAssociations);
        }
コード例 #2
0
 partial void DeleteCustomer(Customer instance);
コード例 #3
0
 partial void InsertCustomer(Customer instance);
コード例 #4
0
 partial void UpdateCustomer(Customer instance);
コード例 #5
0
 private bool FilterCustomer(Customer entity)
 {
     return (entity.CustomerID == this.CustomerID);
 }