public override void AppendDynamicProperties(ODataResource resource, SelectExpandNode selectExpandNode, ResourceContext resourceContext) { // add expanded field //public static EdmNavigationProperty CreateNavigationProperty(IEdmStructuredType declaringType, EdmNavigationPropertyInfo propertyInfo); if (isFirstTime) { selectExpandNode.SelectedNavigationProperties.Add(EdmNavigationProperty.CreateNavigationProperty( new EdmEntityType("EntityTypeNamespace", "EntityTypeName"), new EdmNavigationPropertyInfo() { Name = "PropertyInfoName", Target = new EdmEntityType("EntityTypeNamespace", "EntityTypeName2"), TargetMultiplicity = EdmMultiplicity.One } )); isFirstTime = false; } // add property var list = resource.Properties.ToList(); list.Add(new ODataProperty() { Name = "MyCustomProp", Value = "This Thing" }); resource.Properties = list.AsEnumerable(); base.AppendDynamicProperties(resource, selectExpandNode, resourceContext); }
public ODataNavigationPropertySegmentTests() { _entityType = new EdmEntityType("NS", "Entity"); EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo { Name = "Nav", TargetMultiplicity = EdmMultiplicity.One, Target = _entityType }; _property = EdmNavigationProperty.CreateNavigationProperty(_entityType, propertyInfo); }
private static IEdmNavigationSource GetContainedEntitySet(EdmModel model, EdmEntityType type) { EdmEntitySet entitySet = GetEntitySet(model, type); var containedEntity = GetContainedEntityType(model); var navigationPropertyInfo = new EdmNavigationPropertyInfo() { Name = "nav", Target = containedEntity, TargetMultiplicity = EdmMultiplicity.Many, // todo: TargetMultiplicity info seems lost in V4 ContainsTarget = true }; EdmNavigationProperty navigationProperty = EdmNavigationProperty.CreateNavigationProperty(type, navigationPropertyInfo); type.AddUnidirectionalNavigation(navigationPropertyInfo); IEdmNavigationSource containedEntitySet = entitySet.FindNavigationTarget(navigationProperty); return(containedEntitySet); }
public void KindPropertyReturnsNavigationProperty() { // Arrange EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo { Name = "Nav", TargetMultiplicity = EdmMultiplicity.One, Target = _compositeKeyEntityType }; var property = EdmNavigationProperty.CreateNavigationProperty(_simpleKeyEntityType, propertyInfo); ODataNavigationPropertySegment npSegment = new ODataNavigationPropertySegment(property); ODataNavigationSourceSegment nsSegment = new ODataNavigationSourceSegment(_simpleKeyEntitySet); ODataKeySegment keySegment = new ODataKeySegment(_simpleKeyEntityType); ODataPath path = new ODataPath(nsSegment, keySegment, npSegment); // Act & Assert Assert.Equal(ODataPathKind.NavigationProperty, path.Kind); }
public void Build(EntityTypeInfo typeInfo) { foreach ((PropertyInfo many, PropertyInfo join) in GetManyToManyInfo(_metadataProvider, typeInfo.ClrType)) { if (many == null || many.DeclaringType != typeInfo.ClrType) { continue; } IEdmNavigationProperty joinNavigationProperty = GetJoinNavigationProperty(typeInfo, join.DeclaringType); if (joinNavigationProperty == null) { continue; } EntityTypeInfo principalInfo = _entityTypeInfos[join.PropertyType]; EntityTypeInfo dependentInfo = _entityTypeInfos[many.DeclaringType]; var edmDependentInfo = new EdmNavigationPropertyInfo() { ContainsTarget = true, Name = many.Name, OnDelete = EdmOnDeleteAction.None, PrincipalProperties = principalInfo.EdmType.DeclaredKey, Target = principalInfo.EdmType, TargetMultiplicity = EdmMultiplicity.Many }; IEdmNavigationProperty edmManyToManyProperty; if (typeInfo.ClrType.GetProperty(many.Name) == null) { IEdmNavigationProperty edmNavigationProperty = EdmNavigationProperty.CreateNavigationProperty(dependentInfo.EdmType, edmDependentInfo); edmManyToManyProperty = new OeEdmNavigationShadowProperty(edmNavigationProperty, many); dependentInfo.EdmType.AddProperty(edmManyToManyProperty); } else { edmManyToManyProperty = dependentInfo.EdmType.AddUnidirectionalNavigation(edmDependentInfo); } var targetNavigationProperty = (IEdmNavigationProperty)_entityTypeInfos[join.DeclaringType].EdmType.GetPropertyIgnoreCase(join.Name); var manyToManyJoinDescription = new ManyToManyJoinDescription(join.DeclaringType, joinNavigationProperty, targetNavigationProperty); _edmModel.SetAnnotationValue(edmManyToManyProperty, manyToManyJoinDescription); } }
public void ParseComputeAsExpandQueryOption() { // Create model EdmModel model = new EdmModel(); EdmEntityType elementType = model.AddEntityType("DevHarness", "Entity"); EdmEntityType targetType = model.AddEntityType("DevHarness", "Navigation"); EdmTypeReference typeReference = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false); targetType.AddProperty(new EdmStructuralProperty(targetType, "Prop1", typeReference)); EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo(); propertyInfo.Name = "Nav1"; propertyInfo.Target = targetType; propertyInfo.TargetMultiplicity = EdmMultiplicity.One; EdmProperty navigation = EdmNavigationProperty.CreateNavigationProperty(elementType, propertyInfo); elementType.AddProperty(navigation); EdmEntityContainer container = model.AddEntityContainer("Default", "Container"); container.AddEntitySet("Entities", elementType); // Define queries and new up parser. Uri root = new Uri("http://host"); Uri url = new Uri("http://host/Entities?$expand=Nav1($compute=cast(Prop1, 'Edm.String') as NavProperty1AsString)"); ODataUriParser parser = new ODataUriParser(model, root, url); // parse and validate SelectExpandClause clause = parser.ParseSelectAndExpand(); List <SelectItem> items = clause.SelectedItems.ToList(); items.Count.Should().Be(1); ExpandedNavigationSelectItem expanded = items[0] as ExpandedNavigationSelectItem; List <ComputeExpression> computes = expanded.ComputeOption.ComputedItems.ToList(); computes.Count.Should().Be(1); computes[0].Alias.ShouldBeEquivalentTo("NavProperty1AsString"); computes[0].Expression.ShouldBeSingleValueFunctionCallQueryNode(); computes[0].Expression.TypeReference.ShouldBeEquivalentTo(typeReference); }
public void ParseComputeAsLevel2ExpandQueryOption() { // Create model EdmModel model = new EdmModel(); EdmEntityType elementType = model.AddEntityType("DevHarness", "Entity"); EdmEntityType targetType = model.AddEntityType("DevHarness", "Navigation"); EdmEntityType subTargetType = model.AddEntityType("DevHarness", "SubNavigation"); EdmTypeReference typeReference = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false); elementType.AddProperty(new EdmStructuralProperty(elementType, "Prop1", typeReference)); targetType.AddProperty(new EdmStructuralProperty(targetType, "Prop1", typeReference)); subTargetType.AddProperty(new EdmStructuralProperty(subTargetType, "Prop1", typeReference)); EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo(); propertyInfo.Name = "Nav1"; propertyInfo.Target = targetType; propertyInfo.TargetMultiplicity = EdmMultiplicity.One; EdmProperty navigation = EdmNavigationProperty.CreateNavigationProperty(elementType, propertyInfo); elementType.AddProperty(navigation); EdmNavigationPropertyInfo subPropertyInfo = new EdmNavigationPropertyInfo(); subPropertyInfo.Name = "SubNav1"; subPropertyInfo.Target = subTargetType; subPropertyInfo.TargetMultiplicity = EdmMultiplicity.One; EdmProperty subnavigation = EdmNavigationProperty.CreateNavigationProperty(targetType, subPropertyInfo); targetType.AddProperty(subnavigation); EdmEntityContainer container = model.AddEntityContainer("Default", "Container"); container.AddEntitySet("Entities", elementType); // Define queries and new up parser. string address = "http://host/Entities?$compute=cast(Prop1, 'Edm.String') as Property1AsString, tolower(Prop1) as Property1Lower&" + "$expand=Nav1($compute=cast(Prop1, 'Edm.String') as NavProperty1AsString;" + "$expand=SubNav1($compute=cast(Prop1, 'Edm.String') as SubNavProperty1AsString))"; Uri root = new Uri("http://host"); Uri url = new Uri(address); ODataUriParser parser = new ODataUriParser(model, root, url); // parse ComputeClause computeClause = parser.ParseCompute(); SelectExpandClause selectClause = parser.ParseSelectAndExpand(); // validate top compute List <ComputeExpression> items = computeClause.ComputedItems.ToList(); items.Count().Should().Be(2); items[0].Alias.ShouldBeEquivalentTo("Property1AsString"); items[0].Expression.ShouldBeSingleValueFunctionCallQueryNode(); items[0].Expression.TypeReference.ShouldBeEquivalentTo(typeReference); items[1].Alias.ShouldBeEquivalentTo("Property1Lower"); items[1].Expression.ShouldBeSingleValueFunctionCallQueryNode(); items[1].Expression.TypeReference.FullName().ShouldBeEquivalentTo("Edm.String"); items[1].Expression.TypeReference.IsNullable.ShouldBeEquivalentTo(true); // tolower is built in function that allows nulls. // validate level 1 expand compute List <SelectItem> selectItems = selectClause.SelectedItems.ToList(); selectItems.Count.Should().Be(1); ExpandedNavigationSelectItem expanded = selectItems[0] as ExpandedNavigationSelectItem; List <ComputeExpression> computes = expanded.ComputeOption.ComputedItems.ToList(); computes.Count.Should().Be(1); computes[0].Alias.ShouldBeEquivalentTo("NavProperty1AsString"); computes[0].Expression.ShouldBeSingleValueFunctionCallQueryNode(); computes[0].Expression.TypeReference.ShouldBeEquivalentTo(typeReference); // validate level 2 expand compute List <SelectItem> subSelectItems = expanded.SelectAndExpand.SelectedItems.ToList(); subSelectItems.Count.Should().Be(1); ExpandedNavigationSelectItem subExpanded = subSelectItems[0] as ExpandedNavigationSelectItem; List <ComputeExpression> subComputes = subExpanded.ComputeOption.ComputedItems.ToList(); subComputes.Count.Should().Be(1); subComputes[0].Alias.ShouldBeEquivalentTo("SubNavProperty1AsString"); subComputes[0].Expression.ShouldBeSingleValueFunctionCallQueryNode(); subComputes[0].Expression.TypeReference.ShouldBeEquivalentTo(typeReference); }