/// <summary> /// Marks the property non-optional on the edm type. /// </summary> /// <param name="edmProperty">The edm property.</param> /// <param name="structuralTypeConfiguration">The edm type being configured.</param> /// <param name="attribute">The <see cref="Attribute"/> found.</param> /// <param name="model">The ODataConventionModelBuilder used to build the model.</param> public override void Apply(PropertyConfiguration edmProperty, StructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute, ODataConventionModelBuilder model) { if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } if (!edmProperty.AddedExplicitly) { StructuralPropertyConfiguration structuralProperty = edmProperty as StructuralPropertyConfiguration; if (structuralProperty != null) { structuralProperty.OptionalProperty = false; } NavigationPropertyConfiguration navigationProperty = edmProperty as NavigationPropertyConfiguration; if (navigationProperty != null && navigationProperty.Multiplicity != EdmMultiplicity.Many) { navigationProperty.Required(); } } }
private void ApplyToStructuralProperty(IEdmModel model, StructuralPropertyConfiguration targetProperty) { Contract.Requires(model != null); Contract.Requires(targetProperty != null); var structuralType = model.FindDeclaredType(StructuralTypeName) as IEdmStructuredType; // the specified type is not a structural type (e.g. entity or complex) if (structuralType == null) { return; } var property = structuralType.FindProperty(targetProperty.Name); // the target property couldn't be found if (property == null) { return; } // aggregate all annotations for a given property var annotations = model.GetAnnotationValue <HashSet <InstanceAnnotation> >(property) ?? new HashSet <InstanceAnnotation>(InstanceAnnotationComparer.Instance); // update the qualified name as needed and add the annotation/term Annotation.QualifiedName = Invariant($"{Namespace}.{Name}"); annotations.Add(Annotation); model.SetAnnotationValue(property, annotations); model.AddTerm(this, Annotation, "Property"); }
public override void Apply(PropertyConfiguration edmProperty, StructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute, ODataConventionModelBuilder model) { if (structuralTypeConfiguration == null) { throw Error.ArgumentNull("structuralTypeConfiguration"); } if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } if (model == null) { throw Error.ArgumentNull("model"); } bool isTypeDataContract = structuralTypeConfiguration.ClrType.GetCustomAttributes(typeof(DataContractAttribute), inherit: true).Any(); DataMemberAttribute dataMember = attribute as DataMemberAttribute; if (isTypeDataContract && dataMember != null && !edmProperty.AddedExplicitly) { // set the name alias if (model.ModelAliasingEnabled && !String.IsNullOrWhiteSpace(dataMember.Name)) { edmProperty.Name = dataMember.Name; } StructuralPropertyConfiguration structuralProperty = edmProperty as StructuralPropertyConfiguration; if (structuralProperty != null) { structuralProperty.OptionalProperty = !dataMember.IsRequired; } NavigationPropertyConfiguration navigationProperty = edmProperty as NavigationPropertyConfiguration; if (navigationProperty != null && navigationProperty.Multiplicity != EdmMultiplicity.Many) { if (dataMember.IsRequired) { navigationProperty.Required(); } else { navigationProperty.Optional(); } } } }
public override void Apply(PropertyConfiguration edmProperty, StructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute) { if (structuralTypeConfiguration == null) { throw Error.ArgumentNull("structuralTypeConfiguration"); } if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } bool isTypeDataContract = structuralTypeConfiguration.ClrType.GetCustomAttributes(typeof(DataContractAttribute), inherit: true).Any(); DataMemberAttribute dataMember = attribute as DataMemberAttribute; if (isTypeDataContract && dataMember != null && !edmProperty.AddedExplicitly) { StructuralPropertyConfiguration structuralProperty = edmProperty as StructuralPropertyConfiguration; if (structuralProperty != null) { structuralProperty.OptionalProperty = !dataMember.IsRequired; } NavigationPropertyConfiguration navigationProperty = edmProperty as NavigationPropertyConfiguration; if (navigationProperty != null && navigationProperty.Multiplicity != EdmMultiplicity.Many) { if (dataMember.IsRequired) { navigationProperty.Required(); } else { navigationProperty.Optional(); } } } }