public CsdlSemanticsEntitySetTests() { var referentialConstraints = new List<CsdlReferentialConstraint>(); var csdlNavigation = new CsdlNavigationProperty("Navigation", null, null, null, false, null, referentialConstraints, null, null); this.csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, Enumerable.Empty<CsdlProperty>(), new[] { csdlNavigation }, null, null); var goodBinding = new CsdlNavigationPropertyBinding("Navigation", "EntitySet", null, new CsdlLocation(1, 1)); this.csdlEntitySet = new CsdlEntitySet("EntitySet", "FQ.NS.EntityType", new[] { goodBinding }, null, null); this.csdlContainer = new CsdlEntityContainer("Container", null, new[] { this.csdlEntitySet }, Enumerable.Empty<CsdlSingleton>(), Enumerable.Empty<CsdlOperationImport>(), null, null); var derivedCsdlNavigation = new CsdlNavigationProperty("DerivedNavigation", null, null, null, false, null, referentialConstraints, null, null); var derivedCsdlEntityType = new CsdlEntityType("DerivedEntityType", "FQ.NS.EntityType", false, false, false, null, Enumerable.Empty<CsdlProperty>(), new[] { derivedCsdlNavigation }, null, null); var unrelatedCsdlEntityType = new CsdlEntityType("UnrelatedEntityType", null, false, false, false, null, Enumerable.Empty<CsdlProperty>(), Enumerable.Empty<CsdlNavigationProperty>(), null, null); var csdlSchema = new CsdlSchema("FQ.NS", null, null, new[] { this.csdlEntityType, derivedCsdlEntityType, unrelatedCsdlEntityType }, Enumerable.Empty<CsdlEnumType>(), Enumerable.Empty<CsdlOperation>(),Enumerable.Empty<CsdlTerm>(),Enumerable.Empty<CsdlEntityContainer>(),Enumerable.Empty<CsdlAnnotations>(), Enumerable.Empty<CsdlTypeDefinition>(), null, null); var csdlModel = new CsdlModel(); csdlModel.AddSchema(csdlSchema); var semanticModel = new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty<IEdmModel>()); this.semanticSchema = new CsdlSemanticsSchema(semanticModel, csdlSchema); this.semanticContainer = new CsdlSemanticsEntityContainer(this.semanticSchema, this.csdlContainer); this.semanticEntityType = semanticModel.FindType("FQ.NS.EntityType") as CsdlSemanticsEntityTypeDefinition; this.semanticEntityType.Should().NotBeNull(); this.navigationProperty = this.semanticEntityType.FindProperty("Navigation") as CsdlSemanticsNavigationProperty; this.navigationProperty.Should().NotBeNull(); }
public CsdlSemanticsNavigationPropertyTests() { var constraints = new[] { new CsdlReferentialConstraint("FK", "ID", null, null) }; this.collectionProperty = new CsdlNavigationProperty("Collection", "Collection(FQ.NS.EntityType)", null, "Reference", false, null, constraints, null, null); this.referenceProperty = new CsdlNavigationProperty("Reference", "FQ.NS.EntityType", false, null, false, null, Enumerable.Empty<CsdlReferentialConstraint>(), null, null); var navigationWithoutPartner = new CsdlNavigationProperty("WithoutPartner", "FQ.NS.EntityType", false, null, false, null, Enumerable.Empty<CsdlReferentialConstraint>(), null, null); var idProperty = new CsdlProperty("ID", new CsdlNamedTypeReference("Edm.Int32", false, null), false, null, null, null); var fkProperty = new CsdlProperty("FK", new CsdlNamedTypeReference("Edm.Int32", false, null), false, null, null, null); this.csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, new CsdlKey(new[] { new CsdlPropertyReference("ID", null) }, null), new[] { idProperty, fkProperty }, new[] { collectionProperty, referenceProperty, navigationWithoutPartner }, null, null); var csdlSchema = new CsdlSchema("FQ.NS", null, null, new[] { this.csdlEntityType }, Enumerable.Empty<CsdlEnumType>(), Enumerable.Empty<CsdlOperation>(),Enumerable.Empty<CsdlTerm>(),Enumerable.Empty<CsdlEntityContainer>(),Enumerable.Empty<CsdlAnnotations>(), Enumerable.Empty<CsdlTypeDefinition>(), null, null); var csdlModel = new CsdlModel(); csdlModel.AddSchema(csdlSchema); var semanticModel = new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty<IEdmModel>()); this.semanticEntityType = semanticModel.FindType("FQ.NS.EntityType") as CsdlSemanticsEntityTypeDefinition; this.semanticEntityType.Should().NotBeNull(); this.semanticCollectionNavigation = this.semanticEntityType.FindProperty("Collection") as CsdlSemanticsNavigationProperty; this.semanticReferenceNavigation = this.semanticEntityType.FindProperty("Reference") as CsdlSemanticsNavigationProperty; this.semanticNavigationWithoutPartner = this.semanticEntityType.FindProperty("WithoutPartner") as CsdlSemanticsNavigationProperty; this.semanticCollectionNavigation.Should().NotBeNull(); this.semanticReferenceNavigation.Should().NotBeNull(); this.semanticNavigationWithoutPartner.Should().NotBeNull(); }
internal static CsdlSchema Schema( string namespaceName, string alias = null, Version version = null, CsdlStructuredType[] csdlStructuredTypes = default(CsdlStructuredType[]), CsdlEnumType[] csdlEnumTypes = default(CsdlEnumType[]), CsdlOperation[] csdlOperations = default(CsdlOperation[]), CsdlTerm[] csdlTerms = default(CsdlTerm[]), CsdlEntityContainer[] csdlEntityContainers = default(CsdlEntityContainer[]), CsdlAnnotations[] csdlAnnotations = default(CsdlAnnotations[]), CsdlTypeDefinition[] csdlTypeDefinitions = default(CsdlTypeDefinition[]), CsdlDocumentation documentation = null, CsdlLocation location = null) { if (csdlStructuredTypes == null) { csdlStructuredTypes = new CsdlStructuredType[] { }; } if (csdlEnumTypes == null) { csdlEnumTypes = new CsdlEnumType[] { }; } if (csdlOperations == null) { csdlOperations = new CsdlOperation[] { }; } if (csdlTerms == null) { csdlTerms = new CsdlTerm[] { }; } if (csdlEntityContainers == null) { csdlEntityContainers = new CsdlEntityContainer[] { }; } if (csdlAnnotations == null) { csdlAnnotations = new CsdlAnnotations[] { }; } if (csdlTypeDefinitions == null) { csdlTypeDefinitions = new CsdlTypeDefinition[] { }; } var csdlSchema = new CsdlSchema( namespaceName, alias, version, csdlStructuredTypes, csdlEnumTypes, csdlOperations, csdlTerms, csdlEntityContainers, csdlAnnotations, csdlTypeDefinitions, documentation /*documentation*/, location /*location*/); return csdlSchema; }
public void AddSchema(CsdlSchema schema) { this.schemata.Add(schema); }
private void AddSchema(CsdlSchema schema, bool addAnnotations) { CsdlSemanticsSchema schemaWrapper = new CsdlSemanticsSchema(this, schema); this.schemata.Add(schemaWrapper); foreach (IEdmSchemaType type in schemaWrapper.Types) { CsdlSemanticsStructuredTypeDefinition structuredType = type as CsdlSemanticsStructuredTypeDefinition; if (structuredType != null) { string baseTypeNamespace; string baseTypeName; string baseTypeFullName = ((CsdlNamedStructuredType)structuredType.Element).BaseTypeName; if (baseTypeFullName != null) { EdmUtil.TryGetNamespaceNameFromQualifiedName(baseTypeFullName, out baseTypeNamespace, out baseTypeName); if (baseTypeName != null) { List<IEdmStructuredType> derivedTypes; if (!this.derivedTypeMappings.TryGetValue(baseTypeName, out derivedTypes)) { derivedTypes = new List<IEdmStructuredType>(); this.derivedTypeMappings[baseTypeName] = derivedTypes; } // TODO: REF referenced derived types derivedTypes.Add(structuredType); } } } RegisterElement(type); } foreach (IEdmOperation function in schemaWrapper.Operations) { RegisterElement(function); } foreach (IEdmValueTerm valueTerm in schemaWrapper.ValueTerms) { RegisterElement(valueTerm); } foreach (IEdmEntityContainer container in schemaWrapper.EntityContainers) { RegisterElement(container); } if (!string.IsNullOrEmpty(schema.Alias)) { this.SetNamespaceAlias(schema.Namespace, schema.Alias); } if (addAnnotations) { foreach (CsdlAnnotations schemaOutOfLineAnnotations in schema.OutOfLineAnnotations) { string target = schemaOutOfLineAnnotations.Target; string replaced = this.ReplaceAlias(target); if (replaced != null) { target = replaced; } List<CsdlSemanticsAnnotations> annotations; if (!this.outOfLineAnnotations.TryGetValue(target, out annotations)) { annotations = new List<CsdlSemanticsAnnotations>(); this.outOfLineAnnotations[target] = annotations; } annotations.Add(new CsdlSemanticsAnnotations(schemaWrapper, schemaOutOfLineAnnotations)); } } var edmVersion = this.GetEdmVersion(); if (edmVersion == null || edmVersion < schema.Version) { this.SetEdmVersion(schema.Version); } }
private void AddSchema(CsdlSchema schema) { this.AddSchema(schema, true); }