private void BuildEntitySetsAndSingletons(InvocationContext context, EdmModel model) { var configuration = context.ApiContext.Configuration; foreach (var property in this.publicProperties) { if (configuration.IsPropertyIgnored(property.Name)) { continue; } var isEntitySet = IsEntitySetProperty(property); if (!isEntitySet) { if (!IsSingletonProperty(property)) { continue; } } var propertyType = property.PropertyType; if (isEntitySet) { propertyType = propertyType.GetGenericArguments()[0]; } var entityType = model.FindDeclaredType(propertyType.FullName) as IEdmEntityType; if (entityType == null) { // Skip property whose entity type has not been declared yet. continue; } var container = model.EnsureEntityContainer(this.targetType); if (isEntitySet) { if (container.FindEntitySet(property.Name) == null) { this.entitySetProperties.Add(property); var addedEntitySet = container.AddEntitySet(property.Name, entityType); this.addedNavigationSources.Add(addedEntitySet); } } else { if (container.FindSingleton(property.Name) == null) { this.singletonProperties.Add(property); var addedSingleton = container.AddSingleton(property.Name, entityType); this.addedNavigationSources.Add(addedSingleton); } } } }
/// <inheritdoc/> public async Task<IEdmModel> GetModelAsync(InvocationContext context, CancellationToken cancellationToken) { Ensure.NotNull(context, "context"); IEdmModel modelReturned = await GetModelReturnedByInnerHandlerAsync(context, cancellationToken); if (modelReturned == null) { // There is no model returned so return an empty model. var emptyModel = new EdmModel(); emptyModel.EnsureEntityContainer(ModelCache.targetType); return emptyModel; } EdmModel edmModel = modelReturned as EdmModel; if (edmModel == null) { // The model returned is not an EDM model. return modelReturned; } ModelCache.ScanForDeclaredPublicProperties(); ModelCache.BuildEntitySetsAndSingletons(context, edmModel); ModelCache.AddNavigationPropertyBindings(edmModel); return edmModel; }
private void BuildFunctions(EdmModel model) { foreach (FunctionMethodInfo functionInfo in this.functionInfos) { var returnTypeReference = GetReturnTypeReference(functionInfo.Method.ReturnType, model); ParameterInfo bindingParameter; bool isBound = TryGetBindingParameter(functionInfo.Method, model, out bindingParameter); var function = new EdmFunction( functionInfo.Namespace, functionInfo.Name, returnTypeReference, isBound, BuildEntitySetPathExpression(returnTypeReference, bindingParameter), functionInfo.IsComposable); BuildOperationParameters(function, functionInfo.Method, model); model.AddElement(function); if (!isBound) { var entitySetReferenceExpression = BuildEntitySetReferenceExpression( model, functionInfo.EntitySet, returnTypeReference); var entityContainer = model.EnsureEntityContainer(this.targetType); entityContainer.AddFunctionImport( function.Name, function, entitySetReferenceExpression); } } }