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(); }
private void AddSchema(CsdlSchema schema, bool addAnnotations) { CsdlSemanticsSchema schemaWrapper = new CsdlSemanticsSchema(this, schema); this.schemata.Add(schemaWrapper); AddSchemaElements(schemaWrapper); if (!string.IsNullOrEmpty(schema.Alias)) { this.SetNamespaceAlias(schema.Namespace, schema.Alias); } if (addAnnotations) { // this adds all out-of-line annotations in the schema regardless of edmx:IncludeAnnotations references in the model AddOutOfLineAnnotationsFromSchema(schema, schemaWrapper, /* includeAnnotationsIndex */ null); } var edmVersion = this.GetEdmVersion(); if (edmVersion == null || edmVersion < schema.Version) { this.SetEdmVersion(schema.Version); } }
/// <summary> /// Adds the specified <paramref name="schema"/> to this model if /// the schema's namespace or annotations are referenced by the parent model /// </summary> /// <param name="schema">The schema to add</param> /// <param name="parentReferences">The <see cref="CsdlReference"/>s of the parent model.</param> private void AddSchemaIfReferenced(CsdlSchema schema, IEnumerable <CsdlReference> parentReferences) { CsdlSemanticsSchema schemaWrapper = new CsdlSemanticsSchema(this, schema); bool shouldAddSchemaElements; Dictionary <string, List <CsdlIncludeAnnotations> > includeAnnotationsIndex; ProcessSchemaParentReferences(schema, schemaWrapper, parentReferences, out shouldAddSchemaElements, out includeAnnotationsIndex); if (!string.IsNullOrEmpty(schema.Alias)) { this.SetNamespaceAlias(schema.Namespace, schema.Alias); } if (shouldAddSchemaElements) { AddSchemaElements(schemaWrapper); } if (includeAnnotationsIndex.Count > 0) { AddOutOfLineAnnotationsFromSchema(schema, schemaWrapper, includeAnnotationsIndex); } if (shouldAddSchemaElements || includeAnnotationsIndex.Count > 0) { this.schemata.Add(schemaWrapper); var edmVersion = this.GetEdmVersion(); if (edmVersion == null || edmVersion < schema.Version) { this.SetEdmVersion(schema.Version); } } }
/// <summary> /// Adds out-of-line annotations from the specified schema /// if they are referenced in the <paramref name="includeAnnotationsIndex"/> cache. /// </summary> /// <param name="schema">The schema to add annotations from.</param> /// <param name="schemaWrapper">The <see cref="CsdlSemanticsSchema"/> wrapper for the provided schema</param> /// <param name="includeAnnotationsIndex">Cache of the schema's out-of-line <see cref="IEdmIncludeAnnotations"/>s indexed by the term namespace. /// If this dictionary is non-empty, then only annotations that match /// the references will be added. If it's empty, no annotations will be added. If it's null, all annotations /// will be added unconditionally.</param> private void AddOutOfLineAnnotationsFromSchema( CsdlSchema schema, CsdlSemanticsSchema schemaWrapper, Dictionary <string, List <CsdlIncludeAnnotations> > includeAnnotationsIndex) { if (includeAnnotationsIndex != null && includeAnnotationsIndex.Count == 0) { return; } foreach (CsdlAnnotations schemaOutOfLineAnnotations in schema.OutOfLineAnnotations) { string target = this.ReplaceAlias(schemaOutOfLineAnnotations.Target); List <CsdlSemanticsAnnotations> annotations; if (!this.outOfLineAnnotations.TryGetValue(target, out annotations)) { annotations = new List <CsdlSemanticsAnnotations>(); this.outOfLineAnnotations[target] = annotations; } CsdlAnnotations filteredAnnotations = FilterIncludedAnnotations(schemaOutOfLineAnnotations, target, includeAnnotationsIndex); annotations.Add(new CsdlSemanticsAnnotations(schemaWrapper, filteredAnnotations)); } }
public CsdlSemanticsNavigationPropertyTests() { var constraints = new[] { new CsdlReferentialConstraint("FK", "ID", null) }; this.collectionProperty = new CsdlNavigationProperty("Collection", "Collection(FQ.NS.EntityType)", null, "Reference", false, null, constraints, null); this.referenceProperty = new CsdlNavigationProperty("Reference", "FQ.NS.EntityType", false, null, false, null, Enumerable.Empty <CsdlReferentialConstraint>(), null); var navigationWithoutPartner = new CsdlNavigationProperty("WithoutPartner", "FQ.NS.EntityType", false, null, false, null, Enumerable.Empty <CsdlReferentialConstraint>(), null); var idProperty = new CsdlProperty("ID", new CsdlNamedTypeReference("Edm.Int32", false, null), null, null); var fkProperty = new CsdlProperty("FK", new CsdlNamedTypeReference("Edm.Int32", 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); 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); 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(); }
public void TestInitialize() { _MockRepository = new MockRepository(MockBehavior.Strict); _MockRelatedEntityFilterDataProvider = _MockRepository.Create <IRelatedEntityFilterDataProvider>(); _CsdlSchema = new CsdlSchema(); }
public void CsdlSchema_LazyGetEntities_Test() { // Arrange var doc = new CsdlSchema(); // Act // Assert Assert.IsNotNull(doc.Entities); }
public void CsdlSchema_SetEntities_Test() { // Arrange var doc = new CsdlSchema(); var expectedSchemas = new System.Collections.Generic.Dictionary <string, object>(); // Act doc.Entities = expectedSchemas; // Assert Assert.AreEqual(expectedSchemas, doc.Entities); }
public CsdlSemanticsSchema(CsdlSemanticsModel model, CsdlSchema schema) : base(schema) { this.typesCache = new Cache <CsdlSemanticsSchema, IEnumerable <IEdmSchemaType> >(); this.associationsCache = new Cache <CsdlSemanticsSchema, IEnumerable <CsdlSemanticsAssociation> >(); this.functionsCache = new Cache <CsdlSemanticsSchema, IEnumerable <IEdmFunction> >(); this.entityContainersCache = new Cache <CsdlSemanticsSchema, IEnumerable <IEdmEntityContainer> >(); this.valueTermsCache = new Cache <CsdlSemanticsSchema, IEnumerable <IEdmValueTerm> >(); this.labeledExpressionsCache = new Cache <CsdlSemanticsSchema, Dictionary <string, object> >(); this.semanticsLabeledElements = new Dictionary <CsdlLabeledExpression, IEdmLabeledExpression>(); this.ambiguousLabeledExpressions = new Dictionary <List <CsdlLabeledExpression>, IEdmLabeledExpression>(); this.model = model; this.schema = schema; }
/// <summary> /// Process the <see cref="IEdmReference"/>s of the parent model to /// figure out whether the schema's types (entity types, enums, containers, etc.) and annotations should /// be imported /// </summary> /// <param name="schema">The schema to process</param> /// <param name="schemaWrapper">The <see cref="CsdlSemanticsSchema"/> wrapper of <paramref name="schema"/></param> /// <param name="parentReferences">The references in the model that contains the <paramref name="schema"/></param> /// <param name="shouldAddSchemaElements">Whether schema types such entity types, operations, enums, etc. should be added</param> /// <param name="includeAnnotationsIndex">Cache of the schema's out-of-line <see cref="IEdmIncludeAnnotations"/>s indexed by the term namespace</param> private static void ProcessSchemaParentReferences( CsdlSchema schema, CsdlSemanticsSchema schemaWrapper, IEnumerable <IEdmReference> parentReferences, out bool shouldAddSchemaElements, out Dictionary <string, List <IEdmIncludeAnnotations> > includeAnnotationsIndex) { string schemaNamespace = schema.Namespace; shouldAddSchemaElements = false; includeAnnotationsIndex = new Dictionary <string, List <IEdmIncludeAnnotations> >(); foreach (IEdmReference reference in parentReferences) { if (!shouldAddSchemaElements) { // we should add types from this schema if there's at least // one edmx:Include that references this schema's namespace foreach (IEdmInclude include in reference.Includes) { if (include.Namespace == schemaNamespace) { shouldAddSchemaElements = true; break; } } } foreach (IEdmIncludeAnnotations includeAnnotations in reference.IncludeAnnotations) { // index the edmx:IncludeAnnotations by namespace to make it // easier to filter which annotations to import with the schema string termNamespace = includeAnnotations.TermNamespace; List <IEdmIncludeAnnotations> cachedAnnotations; if (!includeAnnotationsIndex.TryGetValue(termNamespace, out cachedAnnotations)) { cachedAnnotations = new List <IEdmIncludeAnnotations>(); includeAnnotationsIndex[termNamespace] = cachedAnnotations; } cachedAnnotations.Add(includeAnnotations); } } }
public void CsdlDocument_Serialization_SuiteMembership_Test() { // Arrange var service = new CsdlSchema(); var doc = new CsdlDocument { Version = "4.01", EntityContainer = "EAF" }; doc.Schemas.Add("EAF", service); var expectedJson = "{\"$Version\":\"4.01\",\"$EntityContainer\":\"EAF\",\"EAF\":{\"$Alias\":\"self\",\"SuiteMembership\":{\"$Kind\":\"EntityType\",\"$Key\":[\"Id\"],\"Id\":{\"$Type\":\"Edm.Int32\"},\"ProductId\":{\"$Type\":\"Edm.Int32\",\"$NavigationKey\":\"Product\"},\"Product\":{\"$Type\":\"self.Product\",\"$Kind\":\"NavigationProperty\",\"$ReferentialConstraint\":{\"LocalProperty\":\"ProductId\",\"ForeignProperty\":\"Id\",\"ProductId\":\"Id\"},\"@EAF.RelatedEntity.Type\":\"Local\"},\"Quantity\":{\"$Type\":\"Edm.Double\"},\"QuantityType\":{\"$Kind\":\"EntityType\",\"$UnderlyingType\":\"Edm.Int32\",\"Inherited\":1,\"Fixed\":2,\"Percentage\":3},\"SuiteId\":{\"$Type\":\"Edm.Int32\"}}}}"; // Act service.Entities.Add("SuiteMembership", typeof(SuiteMembership).ToCsdl()); var json = JsonConvert.SerializeObject(doc); // Assert Assert.AreEqual(expectedJson, json); }
public void CsdlDocument_Serialization_String_Test() { // Arrange var service = new CsdlSchema(); var doc = new CsdlDocument { Version = "1.0", EntityContainer = "EAF" }; doc.Schemas.Add("UserService", service); var expectedJson = "{\"$Version\":\"1.0\",\"$EntityContainer\":\"EAF\",\"UserService\":{\"$Alias\":\"self\",\"User\":{\"Custom\":\"Json\"}}}"; // Act service.Entities.Add("User", JToken.Parse("{ \"Custom\": \"Json\" }")); var json = JsonConvert.SerializeObject(doc); // Assert Assert.AreEqual(expectedJson, json); }
public void CsdlDocument_Serialization_User_Test() { // Arrange var service = new CsdlSchema(); var doc = new CsdlDocument { Version = "4.01", EntityContainer = "EAF" }; doc.Schemas.Add("EAF", service); var expectedJson = "{\"$Version\":\"4.01\",\"$EntityContainer\":\"EAF\",\"EAF\":{\"$Alias\":\"self\",\"User\":{\"$Kind\":\"EntityType\",\"$Key\":[\"Id\"],\"Id\":{\"$Type\":\"Edm.Int32\"},\"Name\":{\"$Type\":\"Edm.String\"},\"UserTypeId\":{\"$Type\":\"Edm.Int32\",\"$NavigationKey\":\"UserType\"},\"UserType\":{\"$Type\":\"self.UserType\",\"$Kind\":\"NavigationProperty\",\"$ReferentialConstraint\":{\"LocalProperty\":\"UserTypeId\",\"ForeignProperty\":\"Id\",\"UserTypeId\":\"Id\"},\"@EAF.RelatedEntity.Type\":\"Local\"},\"UserRoles\":{\"$Type\":\"self.UserRole\",\"$Kind\":\"NavigationProperty\",\"$Nullable\":true,\"$Collection\":true,\"@EAF.RelatedEntity.Type\":\"Mapping\",\"@EAF.RelatedEntity.MappingEntityType\":\"self.UserRoleMembership\"},\"UserGroups\":{\"$Type\":\"self.UserGroup\",\"$Kind\":\"NavigationProperty\",\"$Nullable\":true,\"$Collection\":true,\"@EAF.RelatedEntity.Type\":\"Mapping\",\"@EAF.RelatedEntity.MappingEntityType\":\"self.UserGroupMembership\"}}}}"; // Act service.Entities.Add("User", typeof(User).ToCsdl()); var json = JsonConvert.SerializeObject(doc); // Assert Assert.AreEqual(expectedJson, json); }
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[]), 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, location /*location*/); return(csdlSchema); }
private void AddSchema(CsdlSchema schema) { CsdlSemanticsSchema item = new CsdlSemanticsSchema(this, schema); this.schemata.Add(item); foreach (IEdmSchemaType type in item.Types) { CsdlSemanticsStructuredTypeDefinition definition = type as CsdlSemanticsStructuredTypeDefinition; if (definition != null) { string baseTypeName = ((CsdlNamedStructuredType)definition.Element).BaseTypeName; if (baseTypeName != null) { string str; string str2; EdmUtil.TryGetNamespaceNameFromQualifiedName(baseTypeName, out str, out str2); if (str2 != null) { List <IEdmStructuredType> list; if (!this.derivedTypeMappings.TryGetValue(str2, out list)) { list = new List <IEdmStructuredType>(); this.derivedTypeMappings[str2] = list; } list.Add(definition); } } } base.RegisterElement(type); } foreach (CsdlSemanticsAssociation association in item.Associations) { RegistrationHelper.AddElement <IEdmAssociation>(association, association.Namespace + "." + association.Name, this.associationDictionary, new Func <IEdmAssociation, IEdmAssociation, IEdmAssociation>(CsdlSemanticsModel.CreateAmbiguousAssociationBinding)); } foreach (IEdmFunction function in item.Functions) { base.RegisterElement(function); } foreach (IEdmValueTerm term in item.ValueTerms) { base.RegisterElement(term); } foreach (IEdmEntityContainer container in item.EntityContainers) { base.RegisterElement(container); } foreach (CsdlAnnotations annotations in schema.OutOfLineAnnotations) { List <CsdlSemanticsAnnotations> list2; string target = annotations.Target; string str5 = item.ReplaceAlias(target); if (str5 != null) { target = str5; } if (!this.outOfLineAnnotations.TryGetValue(target, out list2)) { list2 = new List <CsdlSemanticsAnnotations>(); this.outOfLineAnnotations[target] = list2; } list2.Add(new CsdlSemanticsAnnotations(item, annotations)); } foreach (CsdlUsing @using in schema.Usings) { this.SetNamespaceAlias(@using.Namespace, @using.Alias); } Version edmVersion = this.GetEdmVersion(); if ((edmVersion == null) || (edmVersion < schema.Version)) { this.SetEdmVersion(schema.Version); } }
/// <summary> /// Parse CSDL-JSON doc into CsdlModel, error messages are stored in <see cref="JsonParserContext"/> /// </summary> /// <param name="jsonReader">The JSON reader.</param> /// <param name="context">The parser context.</param> /// <returns>Null or parsed <see cref="CsdlModel"/>.</returns> internal static CsdlModel ParseCsdlDocument(ref Utf8JsonReader jsonReader, JsonParserContext context) { Debug.Assert(context != null); JsonDocument jsonDocument = GetJsonDocument(ref jsonReader, context); if (jsonDocument == null) { return(null); } // make sure to dispose the JsonDocument. using (jsonDocument) { JsonElement rootElement = jsonDocument.RootElement; // A CSDL JSON document consists of a single JSON object. if (!rootElement.ValidateValueKind(JsonValueKind.Object, context)) { return(null); } // This document object MUST contain the member $Version. Version version = rootElement.ProcessRequiredProperty("$Version", context, ParseVersion); if (version == null) { return(null); } CsdlModel csdlModel = new CsdlModel { CsdlVersion = version }; IList <IEdmReference> references = null; rootElement.ParseAsObject(context, (propertyName, propertyValue) => { switch (propertyName) { case "$Version": // skip, because processed break; case "$EntityContainer": // The value of $EntityContainer is the namespace-qualified name of the entity container of that service. // So far, i don't know how to use it. So skip it. break; case "$Reference": // The document object MAY contain the member $Reference to reference other CSDL documents. references = ParseReferences(propertyValue, context); break; default: // CSDL document also MAY contain members for schemas. // Each schema's value is an object. if (propertyValue.ValueKind == JsonValueKind.Object) { CsdlSchema schema = SchemaJsonParser.ParseCsdlSchema(propertyName, csdlModel.CsdlVersion, propertyValue, context); if (schema != null) { csdlModel.AddSchema(schema); break; } } context.ReportError(EdmErrorCode.UnexpectedElement, Strings.CsdlJsonParser_UnexpectedJsonMember(context.Path, propertyValue.ValueKind)); break; } }); if (references != null) { csdlModel.AddCurrentModelReferences(references); } return(csdlModel); } }
/// <summary>An IFilterConverter{TEntity} implementation that gets related entity data and uses that to convert the Filter{TEntity}.</summary> /// <param name="csdlSchema">The csdlSchema for all entities.</param> /// <param name="relatedEntityProvider">An implementation of IRelatedEntityProvider. This is not implemented for you.</param> public RelatedEntityFilterConverter(CsdlSchema csdlSchema, IRelatedEntityFilterDataProvider relatedEntityProvider) { _CsdlSchema = csdlSchema ?? throw new System.ArgumentNullException(nameof(csdlSchema)); _RelatedEntityProvider = relatedEntityProvider ?? throw new System.ArgumentNullException(nameof(relatedEntityProvider)); }
private void AddSchema(CsdlSchema schema) { 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; } derivedTypes.Add(structuredType); } } } RegisterElement(type); } foreach (CsdlSemanticsAssociation association in schemaWrapper.Associations) { RegistrationHelper.AddElement(association, association.Namespace + "." + association.Name, this.associationDictionary, CreateAmbiguousAssociationBinding); } foreach (IEdmFunction function in schemaWrapper.Functions) { RegisterElement(function); } foreach (IEdmValueTerm valueTerm in schemaWrapper.ValueTerms) { RegisterElement(valueTerm); } foreach (IEdmEntityContainer container in schemaWrapper.EntityContainers) { RegisterElement(container); } foreach (CsdlAnnotations schemaOutOfLineAnnotations in schema.OutOfLineAnnotations) { string target = schemaOutOfLineAnnotations.Target; string replaced = schemaWrapper.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)); } foreach (CsdlUsing used in schema.Usings) { this.SetNamespaceAlias(used.Namespace, used.Alias); } var edmVersion = this.GetEdmVersion(); if (edmVersion == null || edmVersion < schema.Version) { this.SetEdmVersion(schema.Version); } }
private void AddSchema(CsdlSchema schema) { this.AddSchema(schema, true); }
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 (IEdmTerm valueTerm in schemaWrapper.Terms) { 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); } }
public CsdlSemanticsSchema(CsdlSemanticsModel model, CsdlSchema schema) : base(schema) { this.model = model; this.schema = schema; }