private IEdmModel EntityTypeTermModel()
        {
            var model = new EdmModel();

            var entityTypeElement = new EdmEntityType("NS", "EntityTypeElement");

            entityTypeElement.AddKeys(entityTypeElement.AddStructuralProperty("KeyProperty", EdmCoreModel.Instance.GetInt32(false)));
            entityTypeElement.AddStructuralProperty("IntegerProperty", EdmCoreModel.Instance.GetInt32(true));
            entityTypeElement.AddStructuralProperty("StringProperty", EdmCoreModel.Instance.GetString(true));
            model.AddElement(entityTypeElement);

            var entityTypeTerm = new EdmTerm("NS", "EntityTypeTerm", new EdmEntityTypeReference(entityTypeElement, true));

            model.AddElement(entityTypeTerm);

            var inlineEntityTypeAnnotation = new EdmAnnotation(entityTypeElement, entityTypeTerm, new EdmRecordExpression(
                                                                   new EdmPropertyConstructor("KeyProperty", new EdmIntegerConstant(1)),
                                                                   new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(111)),
                                                                   new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Inline String 111"))));

            inlineEntityTypeAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(inlineEntityTypeAnnotation);

            var outlineEntityTypeAnnotation = new EdmAnnotation(entityTypeTerm, entityTypeTerm, new EdmRecordExpression(
                                                                    new EdmPropertyConstructor("KeyProperty", new EdmIntegerConstant(2)),
                                                                    new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(222)),
                                                                    new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Outline String 222"))));

            model.AddVocabularyAnnotation(outlineEntityTypeAnnotation);

            return(model);
        }
Exemple #2
0
        public static EdmModel FindVocabularyAnnotationAcrossModelValueAnnotationModel()
        {
            var model = new EdmModel();

            var containerOne = new EdmEntityContainer("DefaultNamespace", "ContainerOne");

            model.AddElement(containerOne);

            var termOne = new EdmTerm("DefaultNamespace", "TermOne", EdmCoreModel.Instance.GetString(true));

            model.AddElement(termOne);
            var termTwo = new EdmTerm("DefaultNamespace", "TermTwo", EdmCoreModel.Instance.GetString(true));

            model.AddElement(termTwo);

            var valueAnnotationOne = new EdmAnnotation(
                containerOne,
                termOne,
                new EdmStringConstant("1"));

            valueAnnotationOne.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotationOne);

            return(model);
        }
        private static void AddOptimisticConcurrencyAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target,
                                                               EntityTypeConfiguration entityTypeConfig, EdmTypeMap edmTypeMap)
        {
            IEnumerable <StructuralPropertyConfiguration> concurrencyPropertyies =
                entityTypeConfig.Properties.OfType <StructuralPropertyConfiguration>().Where(property => property.ConcurrencyToken);

            IList <IEdmStructuralProperty> edmProperties = new List <IEdmStructuralProperty>();

            foreach (StructuralPropertyConfiguration property in concurrencyPropertyies)
            {
                IEdmProperty value;
                if (edmTypeMap.EdmProperties.TryGetValue(property.PropertyInfo, out value))
                {
                    var item = value as IEdmStructuralProperty;
                    if (item != null)
                    {
                        edmProperties.Add(item);
                    }
                }
            }

            if (edmProperties.Any())
            {
                // todo: fix SetOptimisticConcurrencyAnnotation to support setting concurrency annotations on singletons
                // https://github.com/OData/odata.net/issues/770
                // model.SetOptimisticConcurrencyAnnotation(target, edmProperties);

                IEdmCollectionExpression collectionExpression = new EdmCollectionExpression(edmProperties.Select(p => new EdmPropertyPathExpression(p.Name)).ToArray());
                IEdmValueTerm            term = Microsoft.OData.Edm.Vocabularies.V1.CoreVocabularyModel.ConcurrencyTerm;

                EdmAnnotation annotation = new EdmAnnotation(target, term, collectionExpression);
                annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
                model.SetVocabularyAnnotation(annotation);
            }
        }
        public static IEdmModel InvalidPropertyTypeUsingIsTypeOnInlineAnnotationModel()
        {
            var model = new EdmModel();

            var bike = new EdmComplexType("NS", "Bike");

            bike.AddStructuralProperty("Color", EdmCoreModel.Instance.GetString(true));
            model.AddElement(bike);

            var car          = new EdmComplexType("NS", "Car");
            var carExpensive = car.AddStructuralProperty("Expensive", new EdmComplexTypeReference(bike, true));

            model.AddElement(car);

            var carTerm = new EdmTerm("NS", "CarTerm", new EdmComplexTypeReference(car, true));

            model.AddElement(carTerm);

            var valueAnnotation = new EdmAnnotation(
                car,
                carTerm,
                new EdmRecordExpression(
                    new EdmPropertyConstructor(carExpensive.Name, new EdmIsTypeExpression(new EdmStringConstant("foo"), EdmCoreModel.Instance.GetString(true)))));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
Exemple #5
0
        public static void SetSearchRestrictionsCapabilitiesAnnotation(this EdmModel model, IEdmEntitySet entitySet, bool searchable, CapabilitiesSearchExpressions unsupported)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (entitySet == null)
            {
                throw new ArgumentNullException("entitySet");
            }

            var target     = entitySet;
            var term       = SearchRestrictionsTerm;
            var name       = new EdmEnumTypeReference(SearchExpressionsType, false).ToStringLiteral((long)unsupported);
            var properties = new IEdmPropertyConstructor[]
            {
                new EdmPropertyConstructor("Searchable", new EdmBooleanConstant(searchable)),
                new EdmPropertyConstructor("UnsupportedExpressions", new EdmEnumMemberReferenceExpression(SearchExpressionsType.Members.Single(m => m.Name == name))),
            };
            var record = new EdmRecordExpression(properties);

            var annotation = new EdmAnnotation(target, term, record);

            annotation.SetSerializationLocation(model, entitySet.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
        public static IEdmModel CastNullableToNonNullableOnInlineAnnotationModel()
        {
            var model = new EdmModel();

            var address = new EdmComplexType("NS", "Address");

            address.AddStructuralProperty("StreetNumber", EdmCoreModel.Instance.GetInt32(true));
            address.AddStructuralProperty("StreetName", EdmCoreModel.Instance.GetString(true));
            model.AddElement(address);

            var friend = new EdmComplexType("NS", "Friend");

            friend.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
            friend.AddStructuralProperty("NickNames", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true)));
            friend.AddStructuralProperty("Address", new EdmComplexTypeReference(address, true));
            model.AddElement(friend);

            var friendInfo = new EdmTerm("NS", "FriendInfo", EdmCoreModel.GetCollection(new EdmComplexTypeReference(friend, true)));

            model.AddElement(friendInfo);

            var valueAnnotationCast = new EdmCastExpression(new EdmCollectionExpression(new EdmStringConstant("foo"), new EdmStringConstant("bar")), new EdmComplexTypeReference(friend, true));
            var valueAnnotation     = new EdmAnnotation(
                friendInfo,
                friendInfo,
                valueAnnotationCast);

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
Exemple #7
0
        public static EdmModel OutOfLineValueAnnotationWithAnnotationModel()
        {
            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);

            EdmAnnotation valueAnnotation = new EdmAnnotation(
                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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        private static void SetCapabilitiesAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, bool value)
        {
            var expression = new EdmBooleanConstant(value);
            var annotation = new EdmAnnotation(target, term, expression);

            annotation.SetSerializationLocation(model, target.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemple #10
0
        private static void SetComputedAnnotation(EdmModel model, IEdmProperty target)
        {
            // when 'target' is <Key> property, V4's 'Computed' also has the meaning of OData V3's 'Identity'.
            var val        = new EdmBooleanConstant(value: true);
            var annotation = new EdmAnnotation(target, CoreVocabularyModel.ComputedTerm, val);

            annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.SetVocabularyAnnotation(annotation);
        }
Exemple #11
0
        public void ExceptionThrowForInvalidPropertyPath()
        {
            EdmModel model = new EdmModel();

            EdmEntityType personType = new EdmEntityType("MyNs", "Person", null, false, false, true);

            personType.AddKeys(personType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            personType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true));

            var container = new EdmEntityContainer("MyNs", "Container");

            model.AddElement(personType);
            container.AddEntitySet("People", personType);
            model.AddElement(container);
            IEdmEntitySet peopleSet = model.FindDeclaredEntitySet("People");

            IEdmPathExpression nameExpression = new EdmPropertyPathExpression("NameName");

            IEdmCollectionExpression collection = new EdmCollectionExpression(new[] { nameExpression });
            IEdmValueTerm            term       = null;

            foreach (var referencedModel in model.ReferencedModels)
            {
                term = referencedModel.FindDeclaredValueTerm("Org.OData.Core.V1.OptimisticConcurrencyControl");

                if (term != null)
                {
                    break;
                }
            }

            Assert.IsNotNull(term);

            EdmAnnotation valueAnnotationOnEntitySet = new EdmAnnotation(peopleSet, term, collection);

            valueAnnotationOnEntitySet.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(valueAnnotationOnEntitySet);

            ODataEntry entry = new ODataEntry
            {
                Properties = new[]
                {
                    new ODataProperty {
                        Name = "ID", Value = 123
                    },
                    new ODataProperty {
                        Name = "Name", Value = "lucy"
                    },
                }
            };

            Action action = () => GetWriterOutputForContentTypeAndKnobValue(entry, model, peopleSet, personType);

            action.ShouldThrow <ODataException>().WithMessage(ErrorStrings.EdmValueUtils_PropertyDoesntExist("MyNs.Person", "NameName"));
        }
Exemple #12
0
        private static void SetCapabilitiesAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, IEnumerable <string> values)
        {
            if (values == null)
            {
                values = new string[0];
            }

            var expression = new EdmCollectionExpression(values.Select(function => new EdmStringConstant(function)));
            var annotation = new EdmAnnotation(target, term, expression);

            annotation.SetSerializationLocation(model, target.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemple #13
0
        public static void SetComputedAnnotation(EdmModel model, IEdmProperty target)
        {
            EdmUtil.CheckArgumentNull(model, "model");
            EdmUtil.CheckArgumentNull(target, "target");

            IEdmBooleanConstantExpression val = new EdmBooleanConstant(true);
            IEdmValueTerm term = CoreVocabularyModel.ComputedTerm;

            Debug.Assert(term != null, "term!=null");
            EdmAnnotation annotation = new EdmAnnotation(target, term, val);

            annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.SetVocabularyAnnotation(annotation);
        }
Exemple #14
0
        private static void SetVocabularyAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target,
                                                    IList <IEdmPropertyConstructor> properties, string qualifiedName)
        {
            Contract.Assert(model != null);
            Contract.Assert(target != null);

            IEdmValueTerm term = model.FindValueTerm(qualifiedName);

            if (term != null)
            {
                IEdmRecordExpression record     = new EdmRecordExpression(properties);
                EdmAnnotation        annotation = new EdmAnnotation(target, term, record);
                annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
                model.SetVocabularyAnnotation(annotation);
            }
        }
Exemple #15
0
        public static IEdmModel ValueAnnotationInvalidTypeReferenceDurationConstantModel()
        {
            var model     = new EdmModel();
            var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetDuration(true));

            model.AddElement(valueTerm);

            var valueAnnotation = new EdmAnnotation(
                valueTerm,
                valueTerm,
                new EdmDurationConstant(EdmCoreModel.Instance.GetDateTimeOffset(false), new TimeSpan(1, 99, 99, 99, 999)));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
Exemple #16
0
        public static IEdmModel ValueAnnotationValidDefaultDurationConstantModel()
        {
            var model     = new EdmModel();
            var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetDuration(true));

            model.AddElement(valueTerm);

            var valueAnnotation = new EdmAnnotation(
                valueTerm,
                valueTerm,
                new EdmDurationConstant(new TimeSpan()));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
        public static IEdmModel InvalidPropertyTypeUsingIsTypeOnOutOfLineAnnotationModel()
        {
            var model = new EdmModel();

            var friendName = new EdmTerm("NS", "FriendName", EdmCoreModel.Instance.GetString(true));

            model.AddElement(friendName);

            var valueAnnotation = new EdmAnnotation(
                friendName,
                friendName,
                new EdmIsTypeExpression(new EdmStringConstant("foo"), EdmCoreModel.Instance.GetString(true)));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
        public static IEdmModel IsTypeResultFalseEvaluationModel()
        {
            var model = new EdmModel();

            var booleanFlag = new EdmTerm("NS", "BooleanFlag", EdmCoreModel.Instance.GetBoolean(true));

            model.AddElement(booleanFlag);

            var valueAnnotation = new EdmAnnotation(
                booleanFlag,
                booleanFlag,
                new EdmIsTypeExpression(new EdmIntegerConstant(32), EdmCoreModel.Instance.GetString(true)));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
Exemple #19
0
        private static void SetCapabilitiesAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, IEdmValueTerm term, bool value, IEnumerable <IEdmNavigationProperty> navigationProperties, string name1, string name2)
        {
            if (navigationProperties == null)
            {
                navigationProperties = new IEdmNavigationProperty[0];
            }

            var properties = new IEdmPropertyConstructor[]
            {
                new EdmPropertyConstructor(name1, new EdmBooleanConstant(value)),
                new EdmPropertyConstructor(name2, new EdmCollectionExpression(navigationProperties.Select(p => new EdmNavigationPropertyPathExpression(p.Name)))),
            };
            var record = new EdmRecordExpression(properties);

            var annotation = new EdmAnnotation(target, term, record);

            annotation.SetSerializationLocation(model, target.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemple #20
0
        public static void SetScaleMeasuresAnnotation(this EdmModel model, IEdmProperty property, byte scale)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var target     = property;
            var term       = ScaleTerm;
            var expression = new EdmIntegerConstant(scale);
            var annotation = new EdmAnnotation(target, term, expression);

            annotation.SetSerializationLocation(model, property.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemple #21
0
        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);
        }
Exemple #22
0
        public static void SetNavigationRestrictionsCapabilitiesAnnotation(this EdmModel model, IEdmEntitySet entitySet, CapabilitiesNavigationType type, IEnumerable <Tuple <IEdmNavigationProperty, CapabilitiesNavigationType> > properties)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (entitySet == null)
            {
                throw new ArgumentNullException("entitySet");
            }

            if (properties == null)
            {
                properties = new Tuple <IEdmNavigationProperty, CapabilitiesNavigationType> [0];
            }

            var target = entitySet;
            var term   = NavigationRestrictionsTerm;
            // handle type
            var typeLiteral = new EdmEnumTypeReference(NavigationTypeType, false).ToStringLiteral((long)type);
            // handle properties
            var propertiesExpression = properties.Select(p =>
            {
                var name = new EdmEnumTypeReference(NavigationTypeType, false).ToStringLiteral((long)p.Item2);
                return(new EdmRecordExpression(new IEdmPropertyConstructor[]
                {
                    new EdmPropertyConstructor("NavigationProperty", new EdmNavigationPropertyPathExpression(p.Item1.Name)),
                    new EdmPropertyConstructor("Navigability", new EdmEnumMemberReferenceExpression(NavigationTypeType.Members.Single(m => m.Name == name))),
                }));
            });

            var record = new EdmRecordExpression(new IEdmPropertyConstructor[]
            {
                new EdmPropertyConstructor("Navigability", new EdmEnumMemberReferenceExpression(NavigationTypeType.Members.Single(m => m.Name == typeLiteral))),
                new EdmPropertyConstructor("RestrictedProperties", new EdmCollectionExpression(propertiesExpression))
            });

            var annotation = new EdmAnnotation(target, term, record);

            annotation.SetSerializationLocation(model, entitySet.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemple #23
0
        public static void SetConformanceLevelCapabilitiesAnnotation(this EdmModel model, IEdmEntityContainer container, CapabilitiesConformanceLevelType level)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            var target     = container;
            var term       = ConformanceLevelTerm;
            var name       = new EdmEnumTypeReference(ConformanceLevelTypeType, false).ToStringLiteral((long)level);
            var expression = new EdmEnumMemberReferenceExpression(ConformanceLevelTypeType.Members.Single(m => m.Name == name));
            var annotation = new EdmAnnotation(target, term, expression);

            annotation.SetSerializationLocation(model, container.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemple #24
0
        public static void SetPermissionsCoreAnnotation(this EdmModel model, IEdmProperty property, CorePermission value)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            var target     = property;
            var term       = PermissionsTerm;
            var name       = new EdmEnumTypeReference(PermissionType, false).ToStringLiteral((long)value);
            var expression = new EdmEnumMemberReferenceExpression(PermissionType.Members.Single(m => m.Name == name));
            var annotation = new EdmAnnotation(target, term, expression);

            annotation.SetSerializationLocation(model, property.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
        public static IEdmModel CastResultTrueEvaluationModel()
        {
            var model = new EdmModel();

            var address = new EdmComplexType("NS", "Address");

            address.AddStructuralProperty("StreetNumber", EdmCoreModel.Instance.GetInt32(true));
            address.AddStructuralProperty("StreetName", EdmCoreModel.Instance.GetString(true));
            model.AddElement(address);

            var friend     = new EdmEntityType("NS", "Friend");
            var friendName = friend.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));

            friend.AddKeys(friendName);
            var friendAddress = friend.AddStructuralProperty("Address", new EdmComplexTypeReference(address, true));

            model.AddElement(friend);

            var addressRecord = new EdmRecordExpression(new EdmPropertyConstructor[] {
                new EdmPropertyConstructor("StreetNumber", new EdmIntegerConstant(3)),
                new EdmPropertyConstructor("StreetName", new EdmStringConstant("에O詰 갂คำŚёæ"))
            });

            var friendAddressCast = new EdmCastExpression(addressRecord, new EdmComplexTypeReference(address, true));

            var friendTerm = new EdmTerm("NS", "FriendTerm", new EdmEntityTypeReference(friend, true));

            model.AddElement(friendTerm);

            var valueAnnotation = new EdmAnnotation(
                friend,
                friendTerm,
                new EdmRecordExpression(
                    new EdmPropertyConstructor(friendName.Name, new EdmStringConstant("foo")),
                    new EdmPropertyConstructor(friendAddress.Name, friendAddressCast)));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }
        private IEdmModel CollectionOfComplexTypeTermModel()
        {
            var model = new EdmModel();

            var complexTypeElement = new EdmComplexType("NS", "ComplexTypeElement");

            complexTypeElement.AddStructuralProperty("IntegerProperty", EdmCoreModel.Instance.GetInt32(true));
            complexTypeElement.AddStructuralProperty("StringProperty", EdmCoreModel.Instance.GetString(true));
            model.AddElement(complexTypeElement);

            var collectionOfComplexTypeTerm = new EdmTerm("NS", "CollectionOfComplexTypeTerm", EdmCoreModel.GetCollection(new EdmComplexTypeReference(complexTypeElement, true)));

            model.AddElement(collectionOfComplexTypeTerm);

            var inlineCollectionOfComplexTypeAnnotation = new EdmAnnotation(complexTypeElement, collectionOfComplexTypeTerm, new EdmCollectionExpression(
                                                                                new EdmRecordExpression(
                                                                                    new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(111)),
                                                                                    new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Inline String 111"))),
                                                                                new EdmRecordExpression(
                                                                                    new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(222)),
                                                                                    new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Inline String 222")))));

            inlineCollectionOfComplexTypeAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(inlineCollectionOfComplexTypeAnnotation);

            var outlineCollectionOfComplexTypeAnnotation = new EdmAnnotation(collectionOfComplexTypeTerm, collectionOfComplexTypeTerm, new EdmCollectionExpression(
                                                                                 new EdmRecordExpression(
                                                                                     new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(333)),
                                                                                     new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Outline String 333"))),
                                                                                 new EdmRecordExpression(
                                                                                     new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(444)),
                                                                                     new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Outline String 444"))),
                                                                                 new EdmRecordExpression(
                                                                                     new EdmPropertyConstructor("IntegerProperty", new EdmIntegerConstant(555)),
                                                                                     new EdmPropertyConstructor("StringProperty", new EdmStringConstant("Outline String 555")))));

            model.AddVocabularyAnnotation(outlineCollectionOfComplexTypeAnnotation);

            return(model);
        }
Exemple #27
0
        private static void EnumMemberExpressionDemo()
        {
            Console.WriteLine("EnumMemberExpressionDemo");

            var model      = new EdmModel();
            var personType = new EdmEntityType("TestNS", "Person");

            model.AddElement(personType);
            var pid = personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false);

            personType.AddKeys(pid);
            personType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            var colorType = new EdmEnumType("TestNS2", "Color", true);

            model.AddElement(colorType);
            colorType.AddMember("Cyan", new EdmIntegerConstant(1));
            colorType.AddMember("Blue", new EdmIntegerConstant(2));
            var outColorTerm = new EdmTerm("TestNS", "OutColor", new EdmEnumTypeReference(colorType, true));

            model.AddElement(outColorTerm);
            var exp = new EdmEnumMemberExpression(
                new EdmEnumMember(colorType, "Blue", new EdmIntegerConstant(2))
                );

            var annotation = new EdmAnnotation(personType, outColorTerm, exp);

            annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.SetVocabularyAnnotation(annotation);

            ShowModel(model);

            var ann       = model.FindVocabularyAnnotations <IEdmValueAnnotation>(personType, "TestNS.OutColor").First();
            var memberExp = (IEdmEnumMemberExpression)ann.Value;

            foreach (var member in memberExp.EnumMembers)
            {
                Console.WriteLine(member.Name);
            }
        }
Exemple #28
0
        private static void EdmWriteAnnotationDemo()
        {
            Console.WriteLine("EdmWriteAnnotationDemo");

            var model = new EdmModel();

            var mail = new EdmEntityType("ns", "Mail");

            model.AddElement(mail);
            mail.AddKeys(mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));

            var person = new EdmEntityType("ns", "Person");

            model.AddElement(person);
            person.AddKeys(person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            var mails = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                ContainsTarget     = true,
                Name               = "Mails",
                TargetMultiplicity = EdmMultiplicity.Many,
                Target             = mail,
            });

            var ann1 = new EdmAnnotation(mails, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test1"));

            ann1.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(ann1);

            var container = new EdmEntityContainer("ns", "container");

            model.AddElement(container);
            var people = container.AddEntitySet("People", person);
            var ann2   = new EdmAnnotation(people, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test2"));

            model.AddVocabularyAnnotation(ann2);

            ShowModel(model);
        }
        private IEdmModel TermAppliesToAttributeModel()
        {
            var model = new EdmModel();

            var inlineWithoutAppliesToIntegerTerm = new EdmTerm("NS", "InlineWithoutAppliesToIntegerTerm", EdmCoreModel.Instance.GetInt32(true));

            model.AddElement(inlineWithoutAppliesToIntegerTerm);
            var inlineWithoutAppliesToIntegerAnnotation = new EdmAnnotation(inlineWithoutAppliesToIntegerTerm, inlineWithoutAppliesToIntegerTerm, new EdmIntegerConstant(1));

            inlineWithoutAppliesToIntegerAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(inlineWithoutAppliesToIntegerAnnotation);

            var inlineWithAppliesToIntegerTerm = new EdmTerm("NS", "InlineWithAppliesToIntegerTerm", EdmCoreModel.Instance.GetInt32(true), "Term Property");

            model.AddElement(inlineWithAppliesToIntegerTerm);
            var inlineWithAppliesToIntegerAnnotation = new EdmAnnotation(inlineWithAppliesToIntegerTerm, inlineWithAppliesToIntegerTerm, new EdmIntegerConstant(2));

            inlineWithAppliesToIntegerAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.AddVocabularyAnnotation(inlineWithAppliesToIntegerAnnotation);

            var outlineWithoutAppliesToStringTerm = new EdmTerm("NS", "OutlineWithoutAppliesToStringTerm", EdmCoreModel.Instance.GetString(true));

            model.AddElement(outlineWithoutAppliesToStringTerm);
            var outlineWithoutAppliesToStringAnnotation = new EdmAnnotation(outlineWithoutAppliesToStringTerm, outlineWithoutAppliesToStringTerm, new EdmStringConstant("this is 3"));

            model.AddVocabularyAnnotation(outlineWithoutAppliesToStringAnnotation);

            var outlineWithAppliesToStringTerm = new EdmTerm("NS", "OutlineWithAppliesToStringTerm", EdmCoreModel.Instance.GetString(true), "Property Term");

            model.AddElement(outlineWithAppliesToStringTerm);
            var outlineWithAppliesToStringAnnotation = new EdmAnnotation(outlineWithAppliesToStringTerm, outlineWithAppliesToStringTerm, new EdmStringConstant("this is 4"));

            model.AddVocabularyAnnotation(outlineWithAppliesToStringAnnotation);

            return(model);
        }
        public static IEdmModel IsTypeResultTrueEvaluationModel()
        {
            var model = new EdmModel();

            var booleanFlag = new EdmComplexType("NS", "BooleanFlag");
            var flag        = booleanFlag.AddStructuralProperty("Flag", EdmCoreModel.Instance.GetBoolean(true));

            model.AddElement(booleanFlag);

            var booleanFlagTerm = new EdmTerm("NS", "BooleanFlagTerm", new EdmComplexTypeReference(booleanFlag, true));

            model.AddElement(booleanFlagTerm);

            var valueAnnotation = new EdmAnnotation(
                booleanFlag,
                booleanFlagTerm,
                new EdmRecordExpression(
                    new EdmPropertyConstructor(flag.Name, new EdmIsTypeExpression(new EdmStringConstant("foo"), EdmCoreModel.Instance.GetString(true)))));

            valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
            model.AddVocabularyAnnotation(valueAnnotation);

            return(model);
        }