本文整理汇总了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;
}