private EdmStructuredType BuildStructuredType(RdmStructuredType definition) { var edmType = edmModel.FindType(rdmModel.Namespace.NamespaceName + "." + definition.Name) as EdmStructuredType; // add properties foreach (var prop in definition.Properties) { AddProperty(edmType, prop); } // add keys if (edmType is EdmEntityType entityType) { var keys = definition.Keys.Select(key => (IEdmStructuralProperty)edmType.FindProperty(key.Name)); entityType.AddKeys(keys); } // https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530382 // add functions foreach (var operation in definition.Operations) { if (!(edmType is EdmEntityType)) { throw new InvalidOperationException($"function on complex type at {operation.Position}"); } AddOperation(operation, definition); } return(edmType); }
private EdmStructuredType AddStructuredType(RdmStructuredType definition) { // base type, the Build method ensure that the base type was added before the // sub-type and therefore FindType will succeed. IEdmStructuredType edmBaseType = null; if (definition.BaseType != null) { edmBaseType = edmModel.FindType(rdmModel.Namespace.NamespaceName + "." + definition.BaseType) as EdmStructuredType; if (edmBaseType == null) { throw new TransformationException($"unable to find base type {definition.BaseType} for type {definition.Name}"); } } if (definition.Keys.Any() || HasSingletonOfType(definition) || (edmBaseType != null && edmBaseType.TypeKind == EdmTypeKind.Entity)) { var entity = edmModel.AddEntityType(rdmModel.Namespace.NamespaceName, definition.Name, (IEdmEntityType)edmBaseType, definition.IsAbstract, true); foreach (var annotation in definition.Annotations) { annotationBuilder.AddAnnotation(edmModel, entity, annotation); } return(entity); } else { var complex = edmModel.AddComplexType(rdmModel.Namespace.NamespaceName, definition.Name, (IEdmComplexType)edmBaseType, definition.IsAbstract, true); foreach (var annotation in definition.Annotations) { annotationBuilder.AddAnnotation(edmModel, complex, annotation); } return(complex); } }