public IActionResult Get() { EdmChangedObjectCollection changedCollection = new EdmChangedObjectCollection(DeltaCustomerType); //Changed or Modified objects are represented as EdmDeltaResourceObjects for (int i = 0; i < 10; i++) { dynamic typelessCustomer = new EdmDeltaResourceObject(DeltaCustomerType); typelessCustomer.Id = i; typelessCustomer.Name = string.Format("Name {0}", i); typelessCustomer.FavoriteNumbers = Enumerable.Range(0, i).ToArray(); changedCollection.Add(typelessCustomer); } //Deleted objects are represented as EdmDeltaDeletedObjects for (int i = 10; i < 15; i++) { dynamic typelessCustomer = new EdmDeltaDeletedResourceObject(DeltaCustomerType); typelessCustomer.Id = new Uri(i.ToString(), UriKind.RelativeOrAbsolute); typelessCustomer.Reason = DeltaDeletedEntryReason.Deleted; changedCollection.Add(typelessCustomer); } return(Ok(changedCollection)); }
public ODataDeltaResourceSetSerializerTests() { _model = SerializationTestsHelpers.SimpleCustomerOrderModel(); _customerSet = _model.EntityContainer.FindEntitySet("Customers"); _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer))); _path = new ODataPath(new EntitySetSegment(_customerSet)); _customers = new[] { new Customer() { FirstName = "Foo", LastName = "Bar", ID = 10, HomeAddress = new Address() { Street = "Street", ZipCode = null, } }, new Customer() { FirstName = "Foo", LastName = "Bar", ID = 42, } }; _deltaResourceSetCustomers = new EdmChangedObjectCollection(_customerSet.EntityType()); EdmDeltaResourceObject newCustomer = new EdmDeltaResourceObject(_customerSet.EntityType()); newCustomer.TrySetPropertyValue("ID", 10); newCustomer.TrySetPropertyValue("FirstName", "Foo"); EdmComplexObject newCustomerAddress = new EdmComplexObject(_model.FindType("Default.Address") as IEdmComplexType); newCustomerAddress.TrySetPropertyValue("Street", "Street"); newCustomerAddress.TrySetPropertyValue("ZipCode", null); newCustomer.TrySetPropertyValue("HomeAddress", newCustomerAddress); _deltaResourceSetCustomers.Add(newCustomer); _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection(); _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model, Path = _path }; }