public void EFDomainService_AddUnmodifiedScenario() { // create an updated order with an attached new detail NorthwindModel.Order order = new NorthwindModel.Order { OrderID = 1, ShipCity = "London" }; NorthwindModel.Order origOrder = new NorthwindModel.Order { OrderID = 1, ShipCity = "Paris" }; NorthwindModel.Order_Detail detail = new NorthwindModel.Order_Detail { OrderID = 1, ProductID = 1 }; NorthwindModel.Order_Detail detail2 = new NorthwindModel.Order_Detail { OrderID = 1, ProductID = 2 }; order.Order_Details.Add(detail); order.Order_Details.Add(detail2); // create and initialize the service DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(TestDomainServices.EF.Northwind)); TestDomainServices.EF.Northwind nw = new TestDomainServices.EF.Northwind(); DomainServiceContext dsc = new DomainServiceContext(new MockDataService(new MockUser("mathew") { IsAuthenticated = true }), DomainOperationType.Submit); nw.Initialize(dsc); // call attach directly - this causes the detail to be attached as unmodified order.EntityKey = nw.ObjectContext.CreateEntityKey("Orders", order); origOrder.EntityKey = nw.ObjectContext.CreateEntityKey("Orders", order); ObjectContextExtensions.AttachAsModified(nw.ObjectContext.Orders, order, origOrder); // now insert the detail, and verify that even though the detail is already // attached it can be transitioned to new nw.InsertOrderDetail(detail); nw.InsertOrderDetail(detail2); Assert.AreEqual(System.Data.Entity.EntityState.Modified, order.EntityState); Assert.AreEqual(System.Data.Entity.EntityState.Added, detail.EntityState); Assert.AreEqual(System.Data.Entity.EntityState.Added, detail2.EntityState); }