当前位置: 首页>>代码示例>>C#>>正文


C# EdmModel.EnsureEntityContainer方法代码示例

本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.EnsureEntityContainer方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.EnsureEntityContainer方法的具体用法?C# EdmModel.EnsureEntityContainer怎么用?C# EdmModel.EnsureEntityContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Edm.Library.EdmModel的用法示例。


在下文中一共展示了EdmModel.EnsureEntityContainer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildEntitySetsAndSingletons

        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);
                    }
                }
            }
        }
开发者ID:kosinsky,项目名称:RESTier,代码行数:53,代码来源:ConventionBasedApiModelBuilder.cs

示例2: GetModelAsync

            /// <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;
            }
开发者ID:kosinsky,项目名称:RESTier,代码行数:26,代码来源:ConventionBasedApiModelBuilder.cs

示例3: BuildFunctions

        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);
                }
            }
        }
开发者ID:kosinsky,项目名称:RESTier,代码行数:29,代码来源:ConventionBasedOperationProvider.cs


注:本文中的Microsoft.OData.Edm.Library.EdmModel.EnsureEntityContainer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。