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


C# EntityModelSchema.GetComplexType方法代码示例

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


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

示例1: CreateMetadataProperties

        /// <summary>
        /// Creates metadata properties for the specified enumeration of OData OM properties.
        /// </summary>
        /// <param name="model">The model to use.</param>
        /// <param name="owningType">The owning type to which to add the properties.</param>
        /// <param name="properties">Enumeration of the properties to add.</param>
        private static void CreateMetadataProperties(EntityModelSchema model, NamedStructuralType owningType, IEnumerable<ODataProperty> properties)
        {
            if (properties == null)
            {
                return;
            }

            foreach (ODataProperty property in properties)
            {
                ODataPropertyMetadataAnnotation propertyMetadataAnnotation = property.GetInheritedAnnotation<ODataPropertyMetadataAnnotation>();

                object propertyValue = property.Value;
                bool isOpenProperty = false;
                if (propertyMetadataAnnotation != null)
                {
                    isOpenProperty = propertyMetadataAnnotation.IsOpenProperty;
                    ExceptionUtilities.Assert(
                        !isOpenProperty || owningType is EntityType,
                        "Can't declare an open property on non-entity type.");
                    if (propertyMetadataAnnotation.PropertyValueForTypeInference != null)
                    {
                        propertyValue = propertyMetadataAnnotation.PropertyValueForTypeInference;
                    }
                }

                ODataComplexValue complexValue = propertyValue as ODataComplexValue;
                if (complexValue != null)
                {
                    ExceptionUtilities.Assert(complexValue.TypeName.StartsWith(owningType.NamespaceName + "."), "The type name must start with the same namespace as its owning type.");

                    ComplexType complexType = model.GetComplexType(complexValue.TypeName);
                    if (complexType == null)
                    {
                        string complexTypeLocalName = complexValue.TypeName.Substring(owningType.NamespaceName.Length + 1);
                        complexType = model.ComplexType(complexTypeLocalName, owningType.NamespaceName);
                        CreateMetadataProperties(model, complexType, complexValue.Properties);
                    }

                    if (isOpenProperty)
                    {
                        owningType.IsOpen = true;
                    }
                    else
                    {
                        owningType.Property(property.Name, DataTypes.ComplexType.WithDefinition(complexType).Nullable());
                    }
                }
                else
                {
                    bool isKeyProperty = false;
                    bool isETagProperty = false;
                    if (propertyMetadataAnnotation != null)
                    {
                        isKeyProperty = (propertyMetadataAnnotation.Kind & ODataPropertyKind.Key) == ODataPropertyKind.Key;
                        isETagProperty = (propertyMetadataAnnotation.Kind & ODataPropertyKind.ETag) == ODataPropertyKind.ETag;

                        ExceptionUtilities.Assert(
                            !isKeyProperty || owningType is EntityType,
                            "Can't declare a key property on non-entity type.");
                        ExceptionUtilities.Assert(
                            !isETagProperty || owningType is EntityType,
                            "Can't declare an etag property on non-entity type.");
                        ExceptionUtilities.Assert(
                            !isOpenProperty || !(isKeyProperty || isETagProperty),
                            "Key or etag property can't be open.");
                    }

                    if (owningType is EntityType && isOpenProperty)
                    {
                        owningType.IsOpen = true;
                    }
                    else
                    {
                        EntityType owningEntityType = owningType as EntityType;
                        if (owningEntityType != null && isKeyProperty)
                        {
                            ExceptionUtilities.Assert(
                                propertyValue != null,
                                "Found a key property with null value, can't infer type from value in that case and it's invalid anyway.");
                            PrimitiveDataType keyPropertyType = EntityModelUtils.GetPrimitiveEdmType(propertyValue.GetType());
                            owningEntityType.KeyProperty(property.Name, keyPropertyType, isETagProperty);
                        }
                        else
                        {
                            if (propertyValue is ODataCollectionValue)
                            {
                                string itemTypeName = EntityModelUtils.GetCollectionItemTypeName(((ODataCollectionValue)propertyValue).TypeName);
                                CollectionDataType collectionType = null;
                                DataType primitiveItemType = EntityModelUtils.GetPrimitiveEdmType(itemTypeName);
                                if (primitiveItemType != null)
                                {
                                    collectionType = DataTypes.CollectionType.WithElementDataType(primitiveItemType);
                                }
                                else
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:MetadataUtils.cs


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