public void TestSetup() { TestOrder = new PurchaseOrder { PurchaseOrderID = 1 }; TestDetails = new List<PurchaseOrderDetail> { new PurchaseOrderDetail { PurchaseOrderID = 1, PurchaseOrderDetailID = GetUniquePurchaseOrderID() }, new PurchaseOrderDetail { PurchaseOrderID = 1, PurchaseOrderDetailID = GetUniquePurchaseOrderID() }, new PurchaseOrderDetail { PurchaseOrderID = 1, PurchaseOrderDetailID = GetUniquePurchaseOrderID() }, new PurchaseOrderDetail { PurchaseOrderID = 1, PurchaseOrderDetailID = GetUniquePurchaseOrderID() }, new PurchaseOrderDetail { PurchaseOrderID = 1, PurchaseOrderDetailID = GetUniquePurchaseOrderID() }, }; }
partial void UpdatePurchaseOrder(PurchaseOrder instance);
partial void InsertPurchaseOrder(PurchaseOrder instance);
private void attach_PurchaseOrderHeaders(PurchaseOrder entity) { this.SendPropertyChanging(); entity.Vendor = this; }
private void detach_PurchaseOrderHeaders(PurchaseOrder entity) { this.SendPropertyChanging(); entity.ShipMethod = null; }
public void TestQuery_DateTimeSupport() { DomainServiceDescription northwindDescription = DomainServiceDescription.GetDescription(typeof(NorthwindDomainService)); List<PurchaseOrder> poData = new List<PurchaseOrder> { new PurchaseOrder { PurchaseOrderID = 1, OrderDate = new DateTime(2000, 1, 2) }, new PurchaseOrder { PurchaseOrderID = 2, OrderDate = new DateTime(2001, 2, 2) }, new PurchaseOrder { PurchaseOrderID = 3, OrderDate = new DateTime(2002, 3, 2) }, new PurchaseOrder { PurchaseOrderID = 4, OrderDate = new DateTime(2003, 4, 2) }, new PurchaseOrder { PurchaseOrderID = 5, OrderDate = new DateTime(2004, 4, 2) }, new PurchaseOrder { PurchaseOrderID = 6, OrderDate = new DateTime(2005, 4, 2) }, new PurchaseOrder { PurchaseOrderID = 7, OrderDate = new DateTime(2006, 5, 2) }, new PurchaseOrder { PurchaseOrderID = 8, OrderDate = new DateTime(2007, 6, 2) }, new PurchaseOrder { PurchaseOrderID = 8, OrderDate = DateTime.Now.AddDays(1) } }; // Test inline DateTime, verifying that the date's kind is preserved DateTime dt = new DateTime(2002, 3, 3); Expression<Func<PurchaseOrder, bool>> predicate = p => p.OrderDate < new DateTime(2002, 3, 3); IQueryable<PurchaseOrder> query = new PurchaseOrder[0].AsQueryable().Where(predicate); List<ServiceQueryPart> queryParts = QuerySerializer.Serialize(query); Assert.IsTrue(queryParts[0].Expression.Contains(string.Format("DateTime({0},\"{1}\")", dt.Ticks, dt.Kind.ToString()))); IQueryable<PurchaseOrder> resultQuery = (IQueryable<PurchaseOrder>)SystemLinqDynamic.QueryDeserializer.Deserialize(northwindDescription, poData.AsQueryable(), TranslateQueryParts(queryParts)); Assert.IsTrue(resultQuery.ToString().Contains(string.Format("DateTime({0}, {1})", dt.Ticks, dt.Kind.ToString()))); Assert.IsTrue(poData.AsQueryable().Where(predicate).OrderBy(p => p.PurchaseOrderID).SequenceEqual(resultQuery.OrderBy(p => p.PurchaseOrderID))); // Test member access of DateTime (funcletized local accessor) predicate = p => dt > p.OrderDate; query = new PurchaseOrder[0].AsQueryable().Where(predicate); queryParts = QuerySerializer.Serialize(query); Assert.IsTrue(queryParts[0].Expression.Contains(string.Format("DateTime({0},\"{1}\")", dt.Ticks, dt.Kind.ToString()))); resultQuery = (IQueryable<PurchaseOrder>)SystemLinqDynamic.QueryDeserializer.Deserialize(northwindDescription, poData.AsQueryable(), TranslateQueryParts(queryParts)); Assert.IsTrue(poData.AsQueryable().Where(predicate).OrderBy(p => p.PurchaseOrderID).SequenceEqual(resultQuery.OrderBy(p => p.PurchaseOrderID))); // Verify DateTime.Now, DateTime.Today, etc. are treated as remote expressions predicate = p => p.OrderDate < DateTime.Now; query = new PurchaseOrder[0].AsQueryable().Where(predicate); queryParts = QuerySerializer.Serialize(query); Assert.IsTrue(queryParts[0].Expression.Contains("DateTime.Now")); resultQuery = (IQueryable<PurchaseOrder>)SystemLinqDynamic.QueryDeserializer.Deserialize(northwindDescription, poData.AsQueryable(), TranslateQueryParts(queryParts)); Assert.IsTrue(poData.AsQueryable().Where(predicate).OrderBy(p => p.PurchaseOrderID).SequenceEqual(resultQuery.OrderBy(p => p.PurchaseOrderID))); // Test DateTime with time components specified dt = new DateTime(2002, 3, 3, 4, 4, 4, 4); predicate = p => p.OrderDate < dt; query = new PurchaseOrder[0].AsQueryable().Where(predicate); queryParts = QuerySerializer.Serialize(query); Assert.IsTrue(queryParts[0].Expression.Contains(string.Format("DateTime({0},\"{1}\")", dt.Ticks, dt.Kind.ToString()))); resultQuery = (IQueryable<PurchaseOrder>)SystemLinqDynamic.QueryDeserializer.Deserialize(northwindDescription, poData.AsQueryable(), TranslateQueryParts(queryParts)); Assert.IsTrue(resultQuery.ToString().Contains(string.Format("DateTime({0}, {1})", dt.Ticks, dt.Kind.ToString()))); Assert.IsTrue(poData.AsQueryable().Where(predicate).OrderBy(p => p.PurchaseOrderID).SequenceEqual(resultQuery.OrderBy(p => p.PurchaseOrderID))); // Verify that the DayOfWeek enumeration can be used. It is evaluated locally to an int, // and promoted to the enum type on the server predicate = p => p.OrderDate.DayOfWeek == DayOfWeek.Sunday; query = new PurchaseOrder[0].AsQueryable().Where(predicate); queryParts = QuerySerializer.Serialize(query); Assert.IsTrue(queryParts[0].Expression.Contains("OrderDate.DayOfWeek==0")); resultQuery = (IQueryable<PurchaseOrder>)SystemLinqDynamic.QueryDeserializer.Deserialize(northwindDescription, poData.AsQueryable(), TranslateQueryParts(queryParts)); Assert.IsTrue(resultQuery.Count() > 0); Assert.IsTrue(poData.AsQueryable().Where(predicate).OrderBy(p => p.PurchaseOrderID).SequenceEqual(resultQuery.OrderBy(p => p.PurchaseOrderID))); // TODO : currently DateTime constructions involving non-local expressions // are not supported predicate = p => p.OrderDate < new DateTime(p.OrderDate.Year, p.OrderDate.Month, 3); query = new PurchaseOrder[0].AsQueryable().Where(predicate); NotSupportedException expectedException = null; try { queryParts = QuerySerializer.Serialize(query); } catch (NotSupportedException e) { expectedException = e; } Assert.AreEqual(OpenRiaServices.DomainServices.Client.Services.Resource.QuerySerialization_NewExpressionsNotSupported, expectedException.Message); }
public void TestQuery_QueryOperatorSupport_Select() { // empty select is supported IQueryable query; query = from p in new Product[0].AsQueryable() select p; query = (IQueryable<Product>)RoundtripQuery(query, BaselineTestData.Products.AsQueryable()); Assert.AreEqual(BaselineTestData.Products.Count(), query.Cast<object>().Count()); // projections are not supported query = from p in new Product[0].AsQueryable() select new { p.Name, p.Color }; Exception expectedException = null; try { List<ServiceQueryPart> queryParts = QuerySerializer.Serialize(query); } catch (NotSupportedException e) { expectedException = e; Assert.AreEqual(String.Format(OpenRiaServices.DomainServices.Client.Services.Resource.QuerySerialization_ProjectionsNotSupported), e.Message); } Assert.IsNotNull(expectedException); // Verify expected exception for unsupported SelectMany query = new PurchaseOrder[0].AsQueryable().SelectMany(p => p.PurchaseOrderDetails); expectedException = null; try { QuerySerializer.Serialize(query); } catch (NotSupportedException e) { expectedException = e; Assert.AreEqual(String.Format(OpenRiaServices.DomainServices.Client.Services.Resource.QuerySerialization_UnsupportedQueryOperator, "SelectMany"), e.Message); } Assert.IsNotNull(expectedException); }
private void AttachPurchaseOrders(PurchaseOrder entity) { entity.Employee = this; }
public void TestEntityRefCaching_Detach() { CatalogEntityContainer container = new CatalogEntityContainer(); PurchaseOrderDetail detail = new PurchaseOrderDetail { PurchaseOrderDetailID = 1, PurchaseOrderID = 1 }; PurchaseOrder order = new PurchaseOrder { PurchaseOrderID = 1 }; container.LoadEntities(new Entity[] { order, detail }); Assert.AreSame(order, detail.PurchaseOrder); // now detach the detail and verify that the // cached entity is still returned container.GetEntitySet<PurchaseOrderDetail>().Detach(detail); Assert.AreSame(order, detail.PurchaseOrder); }
public void TestEntityCaching_NewEntities() { CatalogEntityContainer container = new CatalogEntityContainer(); // add two orders and a detail PurchaseOrder order1 = new PurchaseOrder(); PurchaseOrder order2 = new PurchaseOrder(); PurchaseOrderDetail detail = new PurchaseOrderDetail(); container.GetEntitySet<PurchaseOrder>().Add(order1); container.GetEntitySet<PurchaseOrder>().Add(order2); container.GetEntitySet<PurchaseOrderDetail>().Add(detail); // examine the order ref of the detail - ensure that // no result is returned, since a FK query would match // BOTH orders Assert.IsNull(detail.PurchaseOrder); // now that we've cached a null, make sure that if more // new entities are added, the ref doesn't change container.GetEntitySet<PurchaseOrder>().Add(new PurchaseOrder()); Assert.IsNull(detail.PurchaseOrder); // now assign order1, and remove order2 - make sure that our // ref to order1 remains detail.PurchaseOrder = order1; Assert.AreSame(order1, detail.PurchaseOrder); container.GetEntitySet<PurchaseOrder>().Remove(order2); Assert.AreSame(order1, detail.PurchaseOrder); container.GetEntitySet<PurchaseOrder>().Remove(order1); Assert.IsNull(detail.PurchaseOrder); }
public void TestEntityRefCaching() { CatalogEntityContainer container = new CatalogEntityContainer(); PurchaseOrderDetail detail = new PurchaseOrderDetail { PurchaseOrderDetailID = 1, PurchaseOrderID = 1 }; PurchaseOrder order = new PurchaseOrder { PurchaseOrderID = 1 }; PurchaseOrder order2 = new PurchaseOrder { PurchaseOrderID = 2 }; container.LoadEntities(new Entity[] { order, order2}); container.LoadEntities(new Entity[] { detail }); // force the EntityRef to cache Assert.AreSame(order, detail.PurchaseOrder); // clear the entity set to verify that the cached // entity is cleared EntitySet purchaseOrderSet = container.GetEntitySet<PurchaseOrder>(); purchaseOrderSet.Clear(); Assert.AreEqual(0, purchaseOrderSet.Count); // after the set has been cleared, we expect null Assert.IsNull(detail.PurchaseOrder); // change the FK and verify that we requery again, getting no match // since all orders have been cleared from the set detail.PurchaseOrderID = 2; Assert.AreSame(null, detail.PurchaseOrder); // Reload the order entities and verify we get the // correct order container.LoadEntities(new Entity[] { order, order2 }); Assert.AreSame(order2, detail.PurchaseOrder); // reset the FK and verify that we requery to get the // right entity detail.PurchaseOrderID = 1; Assert.AreSame(order, detail.PurchaseOrder); }
public void TestEntityCollectionCaching() { CatalogEntityContainer container = new CatalogEntityContainer(); PurchaseOrder order = new PurchaseOrder { PurchaseOrderID = 1 }; PurchaseOrderDetail detail1 = new PurchaseOrderDetail { PurchaseOrderID = 1, PurchaseOrderDetailID = 1 }; PurchaseOrderDetail detail2 = new PurchaseOrderDetail { PurchaseOrderID = 1, PurchaseOrderDetailID = 2 }; container.LoadEntities(new Entity[] { order, detail1, detail2 }); Assert.AreEqual(2, order.PurchaseOrderDetails.Count); // now add a couple new details PurchaseOrderDetail detail3 = new PurchaseOrderDetail(); PurchaseOrderDetail detail4 = new PurchaseOrderDetail(); order.PurchaseOrderDetails.Add(detail3); order.PurchaseOrderDetails.Add(detail4); Assert.AreEqual(4, order.PurchaseOrderDetails.Count); // now modify the parent FK, which will cause the cached // results to be reset, but we expect the explicitly added // entities to be retained // Here we're using ApplyState to allow us to set a PK member w/o validation failure // since PK members cannot be changed. This test should really be based on an association // not involving PK, but the test is still valid this way. order.ApplyState(new Dictionary<string, object> { { "PurchaseOrderID", 2 } }); Assert.AreEqual(2, order.PurchaseOrderDetails.Count); Assert.IsTrue(order.PurchaseOrderDetails.Contains(detail3)); Assert.IsTrue(order.PurchaseOrderDetails.Contains(detail4)); }
private bool FilterPurchaseOrders(PurchaseOrder entity) { return (entity.EmployeeID == this.EmployeeID); }
private void DetachPurchaseOrders(PurchaseOrder entity) { entity.Employee = null; }
partial void DeletePurchaseOrder(PurchaseOrder instance);
private void detach_PurchaseOrderHeaders(PurchaseOrder entity) { this.SendPropertyChanging(); entity.Employee = null; }
private bool FilterPurchaseOrder(PurchaseOrder entity) { return (entity.PurchaseOrderID == this.PurchaseOrderID); }