public void ApplyStructuralProperty(IStructuralEntityProperty property, IEntity sourceEntity) { var odataProperty = new ODataProperty { Name = property.EdmPropertyName }; object value; if (property.TryGetValueFromEntity(sourceEntity, out value)) { odataProperty.Value = property.Serialize(value); var attributedValue = value as IAttributedValue; if (attributedValue != null && !attributedValue.IsSignificant()) { odataProperty.InstanceAnnotations = new[] { CreateNullValueAnnotation(NullValueAnnotationType.NotSignificant) }; } else if (value is InvalidValue) { odataProperty.InstanceAnnotations = new[] { CreateNullValueAnnotation(NullValueAnnotationType.NotValid) }; } } else { odataProperty.InstanceAnnotations = new[] { CreateNullValueAnnotation(NullValueAnnotationType.NotProvided) }; } this.structuralProperties.Add(odataProperty); }
public bool TrySetOnEntity(IEntity targetEntity, ODataEntityDto sourceODataEntity, IStructuralEntityProperty property) { object value; if (!sourceODataEntity.TryGetPropertyValue(property, out value)) { return(false); } if (property.IsReadOnly(targetEntity)) { return(false); } return(property.TrySetValueOnEntity(targetEntity, value)); }
public static bool TryGetStructuralOrKeyProperty(this IEntityType entityType, string propertyName, out IStructuralEntityProperty property) { IStructuralProperty foundProperty; if (entityType.TryGetStructuralProperty(propertyName, out foundProperty) || entityType.TryGetKeyProperty(propertyName, out foundProperty)) { property = foundProperty.As <IStructuralEntityProperty>(); return(true); } property = null; return(false); }