/// <summary> /// Initializes static members of the StoreGeneratedPatternAnnotation class. /// </summary> static StoreGeneratedPatternAnnotation() { None = new StoreGeneratedPatternAnnotation { ServerGeneratedOnInsert = false, ServerGeneratedOnUpdate = false, ClientProvidesValueOnInsert = true, ClientProvidesValueOnUpdate = true, Name = "None", }; Identity = new StoreGeneratedPatternAnnotation { ServerGeneratedOnUpdate = false, ServerGeneratedOnInsert = true, ClientProvidesValueOnInsert = false, ClientProvidesValueOnUpdate = false, Name = "Identity", }; Computed = new StoreGeneratedPatternAnnotation { ServerGeneratedOnUpdate = true, ServerGeneratedOnInsert = true, ClientProvidesValueOnInsert = false, ClientProvidesValueOnUpdate = false, Name = "Computed", }; }
/// <summary> /// Initializes static members of the StoreGeneratedPatternAnnotation class. /// </summary> static StoreGeneratedPatternAnnotation() { None = new StoreGeneratedPatternAnnotation { ServerGeneratedOnInsert = false, ServerGeneratedOnUpdate = false, ClientProvidesValueOnInsert = true, ClientProvidesValueOnUpdate = true, Name = "None", }; Identity = new StoreGeneratedPatternAnnotation { ServerGeneratedOnUpdate = false, ServerGeneratedOnInsert = true, ClientProvidesValueOnInsert = false, ClientProvidesValueOnUpdate = false, Name = "Identity", }; Computed = new StoreGeneratedPatternAnnotation { ServerGeneratedOnUpdate = true, ServerGeneratedOnInsert = true, ClientProvidesValueOnInsert = false, ClientProvidesValueOnUpdate = false, Name = "Computed", }; }
/// <summary> /// Generates the concurrency token attribute. /// </summary> /// <param name="memberProperty">The property.</param> /// <returns>Generated attribute</returns> protected override XAttribute GenerateStoreGeneratedPattern(MemberProperty memberProperty) { StoreGeneratedPatternAnnotation annotation = memberProperty.Annotations.OfType <StoreGeneratedPatternAnnotation>().SingleOrDefault(); if (annotation == null) { return(null); } return(new XAttribute(EdmConstants.AnnotationNamespace.GetName("StoreGeneratedPattern"), annotation.Name)); }
private void VerifyPropertiesValues(EntityChangeData entityChange, object entity) { var entityType = this.GetEntityType(entity.GetType()); var serverNamedValues = this.ObjectServices.GetPropertiesValues(entity, entityType); foreach (NamedValue serverNamedValue in serverNamedValues) { object cachedClientValue = entityChange.CachedPropertiesValues[serverNamedValue.Name]; // check if it's store-generated property MemberProperty property = this.GetPropertyWithPath(serverNamedValue.Name, entityType); StoreGeneratedPatternAnnotation storeGenAnnotation = property.Annotations.OfType <StoreGeneratedPatternAnnotation>().SingleOrDefault(); // The client does not perform fix-up on dependent properties, so we skip those properties here. The verification in the protocol tests // is sufficient for ensuring the server behavior is correct if (entityType.GetDependentProperties().Contains(property)) { continue; } bool isMediaLinkEntryInsert = entityType.HasStream() && entityChange.State == EntityStates.Added; if (storeGenAnnotation != null) { bool clientShouldBeUpdated = !isMediaLinkEntryInsert; if (isMediaLinkEntryInsert || (entityChange.State == EntityStates.Modified && storeGenAnnotation.ServerGeneratedOnUpdate)) { // if the product ever supports materializing the property values generated by the server // during an MLE insert, then this can be changed to expect the server values on DSRP.None as well clientShouldBeUpdated = this.currentContextData.AddAndUpdateResponsePreference == DataServiceResponsePreference.IncludeContent; } else if (!isMediaLinkEntryInsert && entityChange.State == EntityStates.Added && storeGenAnnotation.ServerGeneratedOnInsert) { clientShouldBeUpdated = this.currentContextData.AddAndUpdateResponsePreference != DataServiceResponsePreference.NoContent; } var clientValue = this.ObjectServices.GetObjectAdapter(entityType.FullName).GetMemberValue <object>(entityChange.DescriptorData.Entity, serverNamedValue.Name); if (clientShouldBeUpdated) { this.Assert.AreEqual( serverNamedValue.Value, clientValue, ValueComparer.Instance, "Server-generated value should have been propagated back to the client. {0}.{1}", entityChange.DescriptorData.Identity, serverNamedValue.Name); } else { this.Assert.AreEqual( cachedClientValue, clientValue, ValueComparer.Instance, "Server-generated value should NOT have been propagated back to the client. {0}.{1}", entityChange.DescriptorData.Identity, serverNamedValue.Name); } } else { // The value provided on the client should have been saved to the store. this.VerifyPropertyValue( cachedClientValue, serverNamedValue.Value, serverNamedValue.Name, entityChange.DescriptorData.Identity.OriginalString); } } }