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


C# EdmModel.SetMimeType方法代码示例

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


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

示例1: BuildODataAnnotationTestModel

        /// <summary>
        /// Build a test model shared across several tests.
        /// </summary>
        /// <param name="addAnnotations">true if the annotations should be added upon construction; otherwise false.</param>
        /// <returns>Returns the test model.</returns>
        public static IEdmModel BuildODataAnnotationTestModel(bool addAnnotations)
        {
            // The metadata model with OData-specific annotations
            // - default entity container annotation
            // - HasStream annotation on entity type
            // - MimeType annotation on primitive property
            // - MimeType annotation on service operation
            EdmModel model = new EdmModel();

            var addressType = new EdmComplexType(DefaultNamespaceName, "Address");
            addressType.AddStructuralProperty("Street", StringNullableTypeRef);
            var zipProperty = addressType.AddStructuralProperty("Zip", Int32TypeRef);
            model.AddElement(addressType);
            if (addAnnotations)
            {
                model.SetMimeType(zipProperty, "text/plain");
            }

            var personType = new EdmEntityType(DefaultNamespaceName, "PersonType", null, false, false, true);
            personType.AddKeys(personType.AddStructuralProperty("Id", Int32TypeRef));
            var nameProperty = personType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: false));
            personType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, isNullable: false));
            personType.AddStructuralProperty("Picture", EdmPrimitiveTypeKind.Stream, isNullable: false);
            model.AddElement(personType);
            if (addAnnotations)
            {
                model.SetMimeType(nameProperty, "text/plain");
            }

            // set the default container
            EdmEntityContainer container = new EdmEntityContainer(DefaultNamespaceName, "DefaultContainer");
            model.AddElement(container);

            container.AddEntitySet("People", personType);

            // NOTE: Function import parameters and return types must be nullable as per current CSDL spec
            var serviceOp = container.AddFunctionAndFunctionImport(model, "ServiceOperation1", Int32NullableTypeRef);
            var serviceOpFunc = serviceOp.Function.AsEdmFunction();
            serviceOpFunc.AddParameter("a", Int32NullableTypeRef);
            serviceOpFunc.AddParameter("b", StringNullableTypeRef);

            if (addAnnotations)
            {
                model.SetMimeType(serviceOpFunc, "img/jpeg");
            }

            return model;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:53,代码来源:TestModels.cs


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