/// <summary> /// Tries to convert the given value if it is of a type specific to the client library but still able to be mapped to EDM. /// </summary> /// <param name="primitiveValue">The value to convert.</param> /// <param name="type">The expected type of the value or null.</param> /// <param name="convertedValue">The converted value, if conversion was possible.</param> /// <returns>Whether or not conversion was possible.</returns> private static bool TryConvertClientSpecificPrimitiveValue(object primitiveValue, IEdmPrimitiveTypeReference type, out IEdmDelayedValue convertedValue) { byte[] byteArray; if (ClientConvert.TryConvertBinaryToByteArray(primitiveValue, out byteArray)) { type = EnsurePrimitiveType(type, EdmPrimitiveTypeKind.Binary); convertedValue = new EdmBinaryConstant((IEdmBinaryTypeReference)type, byteArray); return(true); } PrimitiveType clientPrimitiveType; if (PrimitiveType.TryGetPrimitiveType(primitiveValue.GetType(), out clientPrimitiveType)) { type = EnsurePrimitiveType(type, clientPrimitiveType.PrimitiveKind); if (clientPrimitiveType.PrimitiveKind == EdmPrimitiveTypeKind.String) { { convertedValue = new EdmStringConstant((IEdmStringTypeReference)type, clientPrimitiveType.TypeConverter.ToString(primitiveValue)); return(true); } } } convertedValue = null; return(false); }
public static EdmModel OutOfLineVocabularyAnnotationWithAnnotationModel() { EdmModel model = new EdmModel(); EdmComplexType simpleType = new EdmComplexType("DefaultNamespace", "SimpleType"); simpleType.AddStructuralProperty("Data", EdmCoreModel.Instance.GetString(true)); model.AddElement(simpleType); EdmTerm note = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true)); model.AddElement(note); EdmVocabularyAnnotation valueAnnotation = new EdmVocabularyAnnotation( simpleType, note, new EdmStringConstant("ComplexTypeNote")); valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine); model.AddVocabularyAnnotation(valueAnnotation); XElement annotationElement = new XElement("{http://foo}Annotation", "1"); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(valueAnnotation, "http://foo", "Annotation", annotation); return(model); }
public static EdmModel NavigationPropertyWithAnnotationModel() { EdmModel model = new EdmModel(); EdmEntityType person = new EdmEntityType("DefaultNamespace", "Person"); EdmStructuralProperty personId = person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false)); person.AddKeys(personId); model.AddElement(person); EdmNavigationProperty friend = person.AddBidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "Friends", Target = person, TargetMultiplicity = EdmMultiplicity.One }, new EdmNavigationPropertyInfo() { Name = "Self", TargetMultiplicity = EdmMultiplicity.One }); IEdmNavigationProperty self = friend.Partner; XElement annotationElement = new XElement("{http://foo}Annotation", "1"); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(friend, "http://foo", "Annotation", annotation); return(model); }
public static EdmModel DifferentAnnotationNamespaceModel() { EdmModel model = new EdmModel(); EdmEntityType simpleType = new EdmEntityType("DefaultNamespace", "SimpleType"); EdmStructuralProperty simpleTypeId = simpleType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false)); simpleType.AddKeys(simpleTypeId); model.AddElement(simpleType); EdmEntityContainer container = new EdmEntityContainer("DefaultNamespace", "Container"); EdmEntitySet simpleSet = container.AddEntitySet("SimpleSet", simpleType); model.AddElement(container); XElement annotationElement = new XElement("{http://foo}Annotation", new XElement("{http://foo1}Child", new XElement("{http://foo2}GrandChild", "1" ) ) ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(simpleSet, "http://foo", "Annotation", annotation); return(model); }
public static EdmModel NestedXElementWithNoValueModel() { EdmModel model = new EdmModel(); EdmComplexType simpleType = new EdmComplexType("DefaultNamespace", "SimpleType"); EdmStructuralProperty simpleTypeId = simpleType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(true)); model.AddElement(simpleType); XElement annotationElement = new XElement("{http://foo}Annotation", new XElement("{http://foo}Child", new XElement("{http://foo}GrandChild", new XElement("{http://foo}GreatGrandChild", new XElement("{http://foo}GreateGreatGrandChild") ) ) ) ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(simpleTypeId, "http://foo", "Annotation", annotation); return(model); }
public void EdmApplyExpression() { var arguments = new IEdmExpression[] { new EdmIntegerConstant(1) }; var appliedExpression = new EdmStringConstant("foo"); var e = new EdmApplyExpression(appliedExpression, arguments); Assert.AreEqual(EdmExpressionKind.OperationApplication, e.ExpressionKind, "e.ExpressionKind"); Assert.AreEqual(appliedExpression, e.AppliedOperation, "e.AppliedFunction"); Assert.AreEqual(arguments, e.Arguments, "e.AppliedFunction"); Assert.IsFalse(e.IsBad(), "e good"); var operation = new EdmFunction("NS", "function", new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true)); var operationReference = new EdmOperationReferenceExpression(operation); e = new EdmApplyExpression(operationReference, arguments); Assert.AreEqual(EdmExpressionKind.OperationApplication, e.ExpressionKind, "e.ExpressionKind"); Assert.AreEqual(operationReference, e.AppliedOperation, "e.AppliedFunction"); Assert.AreEqual(arguments, e.Arguments, "e.AppliedFunction"); Assert.IsFalse(e.IsBad(), "e good"); this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmExpression)null, arguments)); this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmOperation)null, arguments)); this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmOperation)null, arguments.AsEnumerable())); this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(new EdmStringConstant("foo"), null)); this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(operation, null)); this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(operation, (IEnumerable <IEdmExpression>)null)); var ee = new MutableEdmApplyExpression(); Assert.IsNull(ee.AppliedOperation, "ee.AppliedFunction"); Assert.IsNull(ee.Arguments, "ee.Arguments"); Assert.IsTrue(ee.IsBad(), "Expression is bad."); Assert.AreEqual(2, ee.Errors().Count(), "Expression has no errors"); }
public static EdmModel ComplexNamespaceOverlappingModel() { EdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("Default", "Container"); EdmAction simpleOperationAction = new EdmAction("Default", "SimpleFunction", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(simpleOperationAction); EdmActionImport simpleOperation = new EdmActionImport(container, "SimpleFunction", simpleOperationAction); container.AddElement(simpleOperation); model.AddElement(container); XElement annotationElement = new XElement("{http://foo}Annotation", new XElement("{http://foo}Child", new XElement("{http://foo1}GrandChild", new XElement("{http://foo}GreatGrandChild", "1" ) ) ), new XElement("{http://foo1}Child", new XElement("{http://foo}GrandChild", "1" ) ) ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(simpleOperation, "http://foo", "Annotation", annotation); return(model); }
/// <summary> /// Correlates and retrieves custom attribute values for a given element in an Edm model /// from a provided dictionary mapping of attribute names and extension names. /// </summary> /// <param name="model">The Edm model.</param> /// <param name="element">The target element.</param> /// <param name="customXMLAttributesMapping">The dictionary mapping of attribute names and extension names.</param> /// <returns>A dictionary of extension names mapped to the custom attribute values.</returns> private static Dictionary <string, string> GetCustomXMLAtrributesValueMapping(IEdmModel model, IEdmElement element, Dictionary <string, string> customXMLAttributesMapping) { Dictionary <string, string> atrributesValueMap = new(); if ((!customXMLAttributesMapping?.Any() ?? true) || model == null || element == null) { return(atrributesValueMap); } foreach (var item in customXMLAttributesMapping) { string attributeName = item.Key.Split(':').Last(); // example, 'ags:IsHidden' --> 'IsHidden' string extensionName = item.Value; EdmStringConstant customXMLAttribute = model.DirectValueAnnotationsManager.GetDirectValueAnnotations(element)? .Where(x => x.Name.Equals(attributeName, StringComparison.OrdinalIgnoreCase))? .FirstOrDefault()?.Value as EdmStringConstant; string attributeValue = customXMLAttribute?.Value; if (!string.IsNullOrEmpty(attributeValue)) { atrributesValueMap.TryAdd(extensionName, attributeValue); } } return(atrributesValueMap); }
private IEdmValue ComputeValue() { IEdmStringValue value = new EdmStringConstant(new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false), this.annotation.Value); value.SetIsSerializedAsElement(this.model, !this.annotation.IsAttribute); return(value); }
public static EdmModel NestedXElementWithValueModel() { EdmModel model = new EdmModel(); EdmOperation simpleOperation = new EdmFunction("DefaultNamespace", "SimpleFunction", EdmCoreModel.Instance.GetString(true)); model.AddElement(simpleOperation); XElement annotationElement = new XElement("{http://foo}Annotation", "1", new XElement("{http://foo}Child", "2", new XElement("{http://foo}GrandChild", "3", new XElement("{http://foo}GreatGrandChild", "4", new XElement("{http://foo}GreateGreatGrandChild", "5") ) ) ) ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(simpleOperation, "http://foo", "Annotation", annotation); return(model); }
public void TestStringConstant() { var constant = new EdmStringConstant("foo"); Assert.AreEqual(EdmValueKind.String, constant.ValueKind, "Invalid value kind."); this.ValidateEdmValueKindRoundTrip(EdmValueKind.String, EdmCoreModel.Instance.GetString(true), constant); }
private static void SetCoreAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, string value) { var expression = new EdmStringConstant(value); var annotation = new EdmAnnotation(target, term, expression); annotation.SetSerializationLocation(model, target.ToSerializationLocation()); model.AddVocabularyAnnotation(annotation); }
private static IEdmDirectValueAnnotationBinding GetODataAnnotationBinding(IEdmElement annotatable, string localName, string value) { IEdmStringValue value2 = null; if (value != null) { value2 = new EdmStringConstant(EdmCoreModel.Instance.GetString(true), value); } return(new EdmDirectValueAnnotationBinding(annotatable, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", localName, value2)); }
internal static void SetODataAnnotation(this IEdmModel model, IEdmElement annotatable, string localName, string value) { IEdmStringValue value2 = null; if (value != null) { value2 = new EdmStringConstant(EdmCoreModel.Instance.GetString(true), value); } model.SetAnnotationValue(annotatable, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", localName, value2); }
public void XElementAnnotationTestXElementWithWithoutNamespaceCsdl() { EdmModel model = new EdmModel(); EdmComplexType complexType = new EdmComplexType("DefaultNamespace", "ComplexType"); complexType.AddStructuralProperty("Data", EdmCoreModel.Instance.GetString(true)); model.AddElement(complexType); XElement annotationElement = new XElement("EmptyAnnotation"); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); VerifyThrowsException(typeof(InvalidOperationException), () => annotation.SetIsSerializedAsElement(model, true)); }
public void BuildEdmExpression_Works_ForStringValue() { // Arrange IEdmType edmType = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String); // Act IEdmExpression exp = IEdmTermExtensions.BuildEdmExpression(edmType, "This is a test"); // Assert Assert.NotNull(exp); EdmStringConstant constant = Assert.IsType <EdmStringConstant>(exp); Assert.Equal("This is a test", constant.Value); }
/// <summary> /// Sets the annotation with the OData metadata namespace and the specified <paramref name="localName" /> on the <paramref name="annotatable"/>. /// </summary> /// <param name="model">The <see cref="IEdmModel"/> containing the annotations."/></param> /// <param name="annotatable">The <see cref="IEdmElement"/> to set the annotation on.</param> /// <param name="localName">The local name of the annotation to set.</param> /// <param name="value">The value of the annotation to set.</param> internal static void SetAnnotation(this IEdmModel model, IEdmElement annotatable, string localName, string value) { Debug.Assert(model != null, "model != null"); Debug.Assert(annotatable != null, "annotatable != null"); Debug.Assert(!String.IsNullOrEmpty(localName), "!string.IsNullOrEmpty(localName)"); IEdmStringValue stringValue = null; if (value != null) { IEdmStringTypeReference typeReference = EdmCoreModel.Instance.GetString(/*nullable*/true); stringValue = new EdmStringConstant(typeReference, value); } model.SetAnnotationValue(annotatable, CsdlConstants.ODataMetadataNamespace, localName, stringValue); }
public void AddNamespaceForConventionModel_ForProperty() { var builder = new ODataConventionModelBuilder(); builder.EntityType <Customer>(); IEdmModel model = builder.GetEdmModel(); const string namespaceName = "http://my.org/schema"; var type = "Microsoft.AspNet.OData.Test.Customer"; const string localName = "MyCustomAttribute"; // this registers a "myns" namespace on the model model.SetNamespacePrefixMappings(new[] { new KeyValuePair <string, string>("myns", namespaceName), new KeyValuePair <string, string>("kk", "http://foo.bar.com"), }); // set a simple string as the value of the "MyCustomAttribute" annotation on the "RevisionDate" property var stringType = EdmCoreModel.Instance.GetString(true); var value = new EdmStringConstant(stringType, "!MyString!"); model.SetAnnotationValue(((IEdmEntityType)model.FindType(type)).FindProperty("Name"), namespaceName, localName, value); model.SetAnnotationValue(((IEdmEntityType)model.FindType(type)).FindProperty("Id"), "http://foo.bar.com", localName, value); string metadata = GetMetadataDocument(model); string xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx""> <edmx:DataServices> <Schema Namespace=""Microsoft.AspNet.OData.Test"" xmlns:myns=""http://my.org/schema"" xmlns:kk=""http://foo.bar.com"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Customer""> <Key> <PropertyRef Name=""Id"" /> </Key> <Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"" kk:MyCustomAttribute=""!MyString!"" /> <Property Name=""Name"" Type=""Edm.String"" myns:MyCustomAttribute=""!MyString!"" /> </EntityType> </Schema> <Schema Namespace=""Default"" xmlns:myns=""http://my.org/schema"" xmlns:kk=""http://foo.bar.com"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityContainer Name=""Container"" /> </Schema> </edmx:DataServices> </edmx:Edmx>"; Assert.Equal(xml, metadata); }
public static EdmModel TermWithAnnotationModel() { EdmModel model = new EdmModel(); EdmTerm note = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true)); model.AddElement(note); var annotationElement = new XElement("{http://foo}Annotation", 1); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(note, "http://foo", "Annotation", annotation); return(model); }
public static EdmModel EnumWithAnnotationModel() { EdmModel model = new EdmModel(); EdmEnumType spicy = new EdmEnumType("DefaultNamespace", "Spicy"); model.AddElement(spicy); XElement annotationElement = new XElement("{http://foo}Annotation", "1"); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(spicy, "http://foo", "Annotation", annotation); return(model); }
public static EdmModel AnnotationWithoutChildrenModel() { EdmModel model = new EdmModel(); EdmComplexType complexType = new EdmComplexType("DefaultNamespace", "ComplexType"); complexType.AddStructuralProperty("Data", EdmCoreModel.Instance.GetString(true)); model.AddElement(complexType); XElement annotationElement = new XElement("{http://foo}Annotation"); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(complexType, "http://foo", "Annotation", annotation); return(model); }
public static void SetISOCurrencyMeasuresAnnotation(this EdmModel model, IEdmProperty property, string isoCurrency) { if (model == null) { throw new ArgumentNullException("model"); } if (property == null) { throw new ArgumentNullException("property"); } var target = property; var term = ISOCurrencyTerm; var expression = new EdmStringConstant(isoCurrency); var annotation = new EdmAnnotation(target, term, expression); annotation.SetSerializationLocation(model, property.ToSerializationLocation()); model.AddVocabularyAnnotation(annotation); }
public static EdmModel AnnotationWithEntitySetTagInEntityContainerModel() { EdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("Default", "Container"); model.AddElement(container); XElement annotationElement = new XElement("{http://foo}EntitySet", "1" ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(container, "http://foo", "EntitySet", annotation); return(model); }
public static EdmModel SetChildAnnotationAsAnnotationModel() { EdmModel model = new EdmModel(); EdmTerm note = new EdmTerm("DefaultNamespace", "Note", EdmPrimitiveTypeKind.Int16); model.AddElement(note); XElement annotationElement = new XElement("{http://foo}Annotation", new XElement("{http://foo1}Child", "1" ) ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(note, "http://foo1", "Child", annotation); return(model); }
public static EdmModel AnnotationWithValueModel() { EdmModel model = new EdmModel(); EdmOperation simpleOperation = new EdmFunction("DefaultNamespace", "SimpleFunction", EdmCoreModel.Instance.GetString(true)); EdmOperationParameter simpleOperationId = new EdmOperationParameter(simpleOperation, "Id", EdmCoreModel.Instance.GetInt32(true)); simpleOperation.AddParameter(simpleOperationId); model.AddElement(simpleOperation); XElement annotationElement = new XElement("{http://foo}Annotation", "Value 1.0" ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(simpleOperationId, "http://foo", "Annotation", annotation); return(model); }
public static EdmModel AnnotationWithSchemaTagValueModel() { EdmModel model = new EdmModel(); EdmEntityType simpleType = new EdmEntityType("DefaultNamespace", "SimpleType"); EdmStructuralProperty simpleTypeId = simpleType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false)); simpleType.AddKeys(simpleTypeId); model.AddElement(simpleType); XElement annotationElement = new XElement("{http://foo}Annotation", "</Schema>" ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(simpleType, "http://foo", "Annotation", annotation); return(model); }
public static IEdmModel GetEdmModel() { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet <StreamCustomer>("StreamCustomers"); EdmModel model = builder.GetEdmModel() as EdmModel; IEdmEntityType streamCustomerType = model.SchemaElements.OfType <IEdmEntityType>().FirstOrDefault(c => c.Name == "StreamCustomer"); Assert.NotNull(streamCustomerType); IEdmProperty photoProperty = streamCustomerType.FindProperty("Photo"); EdmStringConstant strConstant1 = new EdmStringConstant("application/javascript"); EdmStringConstant strConstant2 = new EdmStringConstant("image/png"); EdmCollectionExpression collectionExpression = new EdmCollectionExpression(strConstant1, strConstant2); EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(photoProperty, CoreVocabularyModel.AcceptableMediaTypesTerm, collectionExpression); annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); model.AddVocabularyAnnotation(annotation); return(model); }
internal static IEnumerable <IEdmDirectValueAnnotation> ConvertCustomAnnotations(MetadataProviderEdmModel model, IEnumerable <KeyValuePair <string, object> > customAnnotations) { if (customAnnotations != null) { foreach (KeyValuePair <string, object> iteratorVariable0 in customAnnotations) { object iteratorVariable1 = iteratorVariable0.Value; Type iteratorVariable2 = (iteratorVariable1 == null) ? null : iteratorVariable1.GetType(); bool iteratorVariable3 = iteratorVariable2 == typeof(XElement); int length = iteratorVariable0.Key.LastIndexOf(":", StringComparison.Ordinal); if (length == -1) { if (!iteratorVariable3) { string iteratorVariable5 = ConvertAttributeAnnotationValue(iteratorVariable0.Value); yield return(new EdmDirectValueAnnotation(string.Empty, iteratorVariable0.Key, new EdmStringConstant(EdmCoreModel.Instance.GetString(true), iteratorVariable5))); } } else { string namespaceUri = iteratorVariable0.Key.Substring(0, length); string name = iteratorVariable0.Key.Substring(length + 1); if ((iteratorVariable1 == null) || !iteratorVariable3) { string iteratorVariable8 = ConvertAttributeAnnotationValue(iteratorVariable0.Value); yield return(new EdmDirectValueAnnotation(namespaceUri, name, new EdmStringConstant(EdmCoreModel.Instance.GetString(true), iteratorVariable8))); } else if ((iteratorVariable1 != null) && (iteratorVariable2 == typeof(XElement))) { XElement xmlElement = (XElement)iteratorVariable1; string iteratorVariable10 = CreateElementAnnotationStringRepresentation(xmlElement); EdmStringConstant iteratorVariable11 = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), iteratorVariable10); iteratorVariable11.SetIsSerializedAsElement(model, true); yield return(new EdmDirectValueAnnotation(namespaceUri, name, iteratorVariable11)); } } } } }
public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes //config.MapHttpAttributeRoutes(); //config.Routes.MapHttpRoute( // name: "DefaultApi", // routeTemplate: "api/{controller}/{id}", // defaults: new { id = RouteParameter.Optional } ///OData routes /// ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet <Product>("Products"); builder.EntitySet <Category>("Categories"); builder.Namespace = "ProductApi"; var model = builder.GetEdmModel(); //var pschema = model.SchemaElements.First(s => s.Name == "Product"); //var ptype = pschema as IEdmEntityType; var ptype = model.FindType("ProductApi.Product") as IEdmEntityType; var value = new EdmStringConstant(EdmCoreModel.Instance.GetString(true), "data"); var m = model.DirectValueAnnotationsManager; m.SetAnnotationValue(ptype.FindProperty("Name"), "jay", "jay", value); //m.SetAnnotationValue() //model.DirectValueAnnotationsManager.SetAnnotationValue() config.MapODataServiceRoute( routeName: "odata", routePrefix: "odata", model: model); RegisterExampleApi(config); }
public IEdmExpression ConvertToStockExpression(IEdmExpression edmExpression, EdmModel stockModel) { IEdmExpression result = null; switch (edmExpression.ExpressionKind) { case EdmExpressionKind.Null: result = EdmNullExpression.Instance; break; case EdmExpressionKind.StringConstant: var tempString = (IEdmStringConstantExpression)edmExpression; result = new EdmStringConstant(tempString.Type != null ? this.ConvertToStockTypeReference(tempString.Type, stockModel).AsString() : null, tempString.Value); break; case EdmExpressionKind.IntegerConstant: var tempInteger = (IEdmIntegerConstantExpression)edmExpression; result = new EdmIntegerConstant(tempInteger.Type != null ? this.ConvertToStockTypeReference(tempInteger.Type, stockModel).AsPrimitive() : null, tempInteger.Value); break; case EdmExpressionKind.Record: var tempRecord = (IEdmRecordExpression)edmExpression; result = new EdmRecordExpression( tempRecord.DeclaredType == null ? null : this.ConvertToStockTypeReference(tempRecord.DeclaredType, stockModel).AsStructured(), tempRecord.Properties.Select(edmProperty => (IEdmPropertyConstructor) new EdmPropertyConstructor(edmProperty.Name, this.ConvertToStockExpression(edmProperty.Value, stockModel)))); break; case EdmExpressionKind.Collection: var tempCollection = (IEdmCollectionExpression)edmExpression; result = new EdmCollectionExpression(tempCollection.Elements.Select(element => this.ConvertToStockExpression(element, stockModel))); break; default: throw new NotImplementedException(); } return(result); }