Example #1
0
        /// <summary>
        /// Gets the reader behavior for null property value on the specified property.
        /// </summary>
        /// <param name="model">The model containing the annotation.</param>
        /// <param name="property">The property to check.</param>
        /// <returns>The behavior to use when reading null value for this property.</returns>
        public static ODataNullValueBehaviorKind NullValueReadBehaviorKind(this IEdmModel model, IEdmProperty property)
        {
            ExceptionUtils.CheckArgumentNotNull(model, "model");
            ExceptionUtils.CheckArgumentNotNull(property, "property");

            ODataEdmPropertyAnnotation annotation = model.GetAnnotationValue <ODataEdmPropertyAnnotation>(property);

            return(annotation == null ? ODataNullValueBehaviorKind.Default : annotation.NullValueReadBehaviorKind);
        }
Example #2
0
        /// <summary>
        /// Adds a transient annotation to indicate how null values for the specified property should be read.
        /// </summary>
        /// <param name="model">The <see cref="IEdmModel"/> containing the annotations.</param>
        /// <param name="property">The <see cref="IEdmProperty"/> to modify.</param>
        /// <param name="nullValueReadBehaviorKind">The new behavior for reading null values for this property.</param>
        public static void SetNullValueReaderBehavior(this IEdmModel model, IEdmProperty property, ODataNullValueBehaviorKind nullValueReadBehaviorKind)
        {
            ExceptionUtils.CheckArgumentNotNull(model, "model");
            ExceptionUtils.CheckArgumentNotNull(property, "property");

            ODataEdmPropertyAnnotation annotation = model.GetAnnotationValue <ODataEdmPropertyAnnotation>(property);

            if (annotation == null)
            {
                if (nullValueReadBehaviorKind != ODataNullValueBehaviorKind.Default)
                {
                    annotation = new ODataEdmPropertyAnnotation
                    {
                        NullValueReadBehaviorKind = nullValueReadBehaviorKind
                    };
                    model.SetAnnotationValue(property, annotation);
                }
            }
            else
            {
                annotation.NullValueReadBehaviorKind = nullValueReadBehaviorKind;
            }
        }